GithubHelp home page GithubHelp logo

ute's Introduction

Avatar

Build Status Dependencies Status Coverage Status Published Version
npm Badge

Ute

Ute is an unframework for simple node.js web application.

This is handy if you want to run your web app by specifying route + environment configuration files and handler functions, with less repetitive boilerplate code.

Under the hood, Ute uses Express, EJS (with Partials), and nconf.

Installation

npm install ute

or as a dependency in package.json file:

"dependencies": {
  "ute": "x.y.z"
}

Usage

Specify handler functions:

function homeCb(req, res) {
  res.render('home.html', {
    layout: 'mylayout',
    locals: {
      name: 'Bob'
    }
  });
}

function dataCb(req, res) {
  res.json({ foo: 'bar' });
}

Create a Ute instance and call start:

var Ute = require('ute');
var ute = new Ute();

var handlers = { home: homeCb, data: dataCb }

ute.start(handlers);

Place mylayout.html and home.html under views directory:

mylayout.html

<html>
<head><title>My Site</title></head>
<body>
  <%- body %>
</body>
</html>

home.html

Hello <%= name %>!

Configuration

Set application name and port in conf/.json:

{
  "app": {
    "name": "myapp",
    "port": 9000
  }
}

Set log4js configuration in conf/-log4js.json, e.g.

{
  "appenders": [
    {
      "type": "console"
    },
    {
      "type": "file",
      "filename": "someapp.log",
      "maxLogSize": 10240000,
      "backups": 10
    }
  ],
  "replaceConsole": true
}

Set routes path and handler mappings in conf/routes.json:

[
  { "method": "GET", "path": "/", "handler": "home" },
  { "method": "POST", "path": "/data", "handler": "data" }
]

Colophon

Developer's Guide

Build reports:

ute's People

Contributors

cliffano avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

voff4eg

ute's Issues

Expose internal app

Hello, there will always be a need for specific configuration and tweaking. The easy way is to expose generated app to the user. I see two methods:

  • make run() return {app:app, express:express}
  • add a callback parameter run(cb) and call it at the end cb(app, express)

The latter one is the best imho as you will be able to handle it properly even if you need async work in the future.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.