Skip to content

Instantly share code, notes, and snippets.

@andypotanin
Last active July 28, 2016 08:08
Show Gist options
  • Select an option

  • Save andypotanin/f20a1f5d9f3958251f1f1a500b539557 to your computer and use it in GitHub Desktop.

Select an option

Save andypotanin/f20a1f5d9f3958251f1f1a500b539557 to your computer and use it in GitHub Desktop.
/**
* Explain What Middleware/Route does.
*
* @author potanin@UD
* @param req
* @param res
* @param next
* @returns {*}
*/
function myMiddleware( req, res, next ) {
// do stuff
// call out helper method that is part of this module
module.exports.someHelperMethod( data, function someHelperMethodCallback( error, data ){
// our someHelperMethod did some work, and now we can do res.send
res.send( data );
});
}
Object.defineProperties( module.exports = myMiddleware, {
someHelperMethod: {
/**
* A method that is available externally and internally.
*
* module.exports.someHelperMethod( data, callback );
*/
value: function someHelperMethod( data, callback ) {
// do something with data, trigger callback
callback( null, {});
},
writable: true,
enumerable: true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment