Calling already defined routes in other routes in Express NodeJS
Similar to what Gates said, but I would keep the function(req, res){} in your routes file. So I would do something like this instead: routes.js var myModule = require(‘myModule’); app.get(“/firstService/:query”, function(req,res){ var html = myModule.firstService(req.params.query); res.end(html) }); app.get(“/secondService/:query”, function(req,res){ var data = myModule.secondService(req.params.query); res.end(data); }); And then in your module have your logic split up … Read more