Last active
July 28, 2016 08:08
-
-
Save andypotanin/f20a1f5d9f3958251f1f1a500b539557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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