Trojan Trojan - 1 year ago 43
Node.js Question

nodejs routing issue among two or more index files

I Am new to nodejs .In routes folder, i have two server files like index.js and college.js...Each server file have some api calls...

how to call appropriate server file for client API request .

for example:::

student signup data API call is in index.js file when he signedup, his details automatically stored into database.. AND .... login API call is in college.js file, here when he logged in, the entered details will be checked whether those r exist or not..

when i call signup from client, its should automatically redirect to appropriate server file for api ..... how to redirect.. can anyone please help to get rid of it

Thank you

Answer Source

If i understand you correctly you need something like this.

In your routes files college and other.

var express = require('express');
var router = express.Router();
router.get("/test", function(req,res){code to handle req and send res.})
module.exports = router;

In main app file. you need to do following

var someRoute = require('./routes/college');
app.use('/college', someRoute);

So after user will go to domain/college the someRoute file routes will handle that request.

And here in documentation

Hope this helps.