teller

Simple node.js webserver.

#teller Simple node.js webserver.
Dependencies: crossroads, ejs, filed, formidable, wrench.

npm install teller
var app = require('teller')
app.get('/', function(reqres) {
  res.json({ foo: 'bar' })
}).listen(1234)

See crossroads.addRoute for more documentation on route patterns. Teller only supports string patterns, and named variables are available in req.route.

Add an GET route with callback.

app.get('/', function(reqres) {
  res.send('<h1>Hello world!</h1>')
})

app.post(route, callback)

Add a POST route with callback.

app.post('/add', function(reqres) {
  res.json(req.body)
})

Add a DELETE route with callback.

app.delete('/image', function(reqres) {
  res.json(req.body)
})

Settings for template rendering and static file serving.

app.settings({
  template: { dir: __dirname+'/templates', 404: '404.ejs' },
  static: { route: '/public', dir: __dirname+'/public' }
})

Begin accepting connections on the specified port.

app.listen(1234)

Contains named variables (see Routing) as key-value pairs.

app.get('/:foo:', function(reqres) {
  console.log(req.route.foo)
  // GET /bar would log 'bar' 
})

Contains a parsed query string for GET requests.

app.get('/qs', function(reqres) {
  console.log(req.query.foo)
  // GET /qs?foo=bar would log 'bar' 
})

Contains a parsed form body for POST & DELETE requests.

app.post('/form', function(reqres) {
  console.log(req.body.foo)
  // POST /form foo=bar would log 'bar' 
})

Render the object as json.

app.get(route, function(reqres) {
  res.json({ foo: bar })
})

Redirect to another url.

app.get(route, function(reqres) {
  res.redirect('/login')
})

Render the specified template. Template directory must be specified in app.settings().

app
  .settings({ dir: __dirname+'/templates' })
  .get(route, function(reqres) {
    res.render('template.ejs', data, statusCode)
  })

Renders a string, with optional Content-Type header and status code.

app.get(route, function(reqres) {
  res.send('<h1>hello</h1>')
})

If settings.template['404'] is supplied, renders a custom 404 page, otherwise sends the default 404 page.

app.get(route, function(reqres) {
  res.show404(data)
})