Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple node.js webserver.
JavaScript
tree: 70d14e8ab0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
.travis.yml
Makefile
README.md
index.js
package.json

README.md

teller

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

Build Status

Installation

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

Routing

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

app.get(route, callback)

Add an GET route with callback.

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

app.post(route, callback)

Add a POST route with callback.

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

app.delete(route, callback)

Add a DELETE route with callback.

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

app.settings(settings)

Settings for template rendering and static file serving.

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

app.listen(port)

Begin accepting connections on the specified port.

app.listen(1234)

Request

req.route

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

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

req.query

Contains a parsed query string for GET requests.

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

req.body

Contains a parsed form body for POST & DELETE requests.

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

Response

res.json(obj [, statusCode])

Render the object as json.

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

res.redirect(url [, statusCode])

Redirect to another url.

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

res.render(template [, data [, statusCode]])

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

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

res.send(data [, contentType [, statusCode]])

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

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

res.show404()

Sends the default 404 page.

app.get(route, function(req, res) {
  res.show404()
})
Something went wrong with that request. Please try again.