I use node.js with the express framework and I have figured out how the routing works.
app.get('/save',webcalender.save);
I have a webcalender file with this function:
exports.save = function(req, res){
res.send(req.query["headline"]);};
But how would I built a different function and use it in there:
exports.test = function() { console.log("test"); }
I have tried:
exports.save = function(req, res){
test(); or webcalender.test or also test = webcalender.test(); and then test;
res.send(req.query["headline"]);};
thanks for you help
This question is a bit unclear.
I assume
savefunction is defined in somewebcalendar.jsand imported withIll break the answer now in two scenarios.
Assuming
testfunction is the samewebcalendar.jsYou can then do something like
Or in one line
And then to use
testin the same module simply calltest();like you did.In case if
testis defined in another moduleLets say in
test.jsthen in order to use it inwebcalendar.jsmodule you have to require it like this:or simply
This should cover most of the cases, if its not please clarify your question since as I said earlier its unclear.
Also I suggest you to familiarize your self with nodejs module to understand why, what and when you need to export, since its not clear from you question why are you exporting the
testfunction (in case if its used only inwebcalendar.jsmodule).Here is another good resource to nodejs require
Good luck!