nodejs express mongodb routes const variable

Multi tool use
nodejs express mongodb routes const variable
I have followed this guide: https://medium.freecodecamp.org/building-a-simple-node-js-api-in-under-30-minutes-a07ea9e390d2 to help me set up a backend for my react app. I am struggling to understand a particular line of code that's causing me to question my understanding of javascript.
module.exports = function(app, db) {
const collection =
app.post('/notes', (req, res) => {...};
app.put('/notes', (req, res) => {...};
app.delete('/notes', (req, res) => {...};
});
};
So is the const collection variable being set to all three functions? If so, is this something you can do with any 2 or more functions just by writing them back to back? Where exactly should I add helper functions that can be used in one or more of these 3 routing functions? Something like this?
module.exports = function(app, db) {
const collection =
helperFunctionForPost = () => {};
helperFunctionForPutAndDelete = () => {};
app.post('/notes', (req, res) => {...};
app.put('/notes', (req, res) => {...};
app.delete('/notes', (req, res) => {...};
});
};
any info about this is highly appreciated!
1 Answer
1
You can add helper function like:app.post('/notes', helperFunctionForPost, (req, res) => {...};
app.post('/notes', helperFunctionForPost, (req, res) => {...};
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.