Created
October 17, 2020 14:53
-
-
Save rebz/5e5a16c8f7811ca42751d28afa6808f8 to your computer and use it in GitHub Desktop.
Example of progressive abstraction for routes in a Node Express application.
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
// OPTION 1 | |
router.get('/user', function(req, res) { | |
res.send('yay') | |
}) | |
// OPTION 2 | |
function getUser(req, res) { | |
res.send('yay') | |
} | |
router.get('/user', getUser) | |
// OPTION 3 | |
const getUser = function(req, res) { | |
res.send('yay') | |
} | |
router.get('/user', getUser) | |
// OPTION 4 | |
const UserController = { | |
getUser: function(req, res) { | |
res.send('yay') | |
} | |
} | |
router.get('/user', UserController.getUser) | |
// OPTION 5 | |
// /controllers/UserController.js | |
module.exports = { | |
login: function(req, res) { | |
res.send('yay') | |
}, | |
register: function(req, res) { | |
} | |
} | |
// routes/index.js | |
const UserController = require('./../controllers/UserController.js') | |
router.get('/user', UserController.getUser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment