Skip to content

Create a new router

Course: PayTM project - chapter 12

All user balances should go to a different express router (that handles all requests on /api/v1/account ).

Create a new router in routes/account.js and add export it

Solution
backend/routes/account.js
const express = require('express');
const router = express.Router();
module.exports = router;

Send all requests from /api/v1/account/* in routes/index.js to the router created in step 1.

Solution
backend/user/index.js
const express = require('express');
const userRouter = require("./user");
const accountRouter = require("./account");
const router = express.Router();
router.use("/user", userRouter);
router.use("/account", accountRouter);
module.exports = router;