Negligent Parachute Maintainers

    teller

    0.9.0 • Public • Published

    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', 404: '404.ejs' },
      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()

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

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

    Keywords

    none

    Install

    npm i teller

    DownloadsWeekly Downloads

    9

    Version

    0.9.0

    License

    none

    Last publish

    Collaborators

    • craigr_