express-functional-control

0.1.1 • Public • Published

express-functional-control

Some tools to make it easier to tie express routes to model functions (inside any controller function). Just getting rid of repetitive stuff like this:

# users.coffee (a controller)
exports.getUser = (req, res) -> 
  User.findOne {userId: req.params.userId}, (err, user) ->
    if err? then return res.send 500, {message: err.message}
    if not user? then return res.send 404
    res.send user

Example of Use:

# users.coffee (a controller)
{send, ok} = require 'express-functional-control'

# sends 200 {object}, 500 {error}, or 404
exports.getUser = (req, res) -> 
  User.findOne {userId: req.params.userId}, send(res)

# sends 200 OK or 500 {error}
exports.saveUser = (req, res) ->
  user = new User req.body
  user.save ok(res)

Readme

Keywords

none

Package Sidebar

Install

npm i express-functional-control

Weekly Downloads

0

Version

0.1.1

License

none

Last publish

Collaborators

  • seanhess