Nuclearly Potent Moonshine
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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)

Keywords

none

install

npm i express-functional-control

Downloadsweekly downloads

1

version

0.1.1

license

none

repository

githubgithub

last publish

collaborators

  • avatar