Nihilist Pocket Monsters
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    express-functional-controlpublic

    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

    Downloadslast 7 days

    1

    version

    0.1.1

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar