In routes
folder->login.js
const express = require("express");
const router = express.Router();
router.get("/products",
(req, res, next) => {
res.send("<h1>Hello From Login
Page</h1>");
//Next
part-> Adding html file to this
//Also
we can define a controller to this function
});
module.exports = router;
In App.js
const
NewRoutsPage = require("./routes/login");
import the routes here
app.use(NewRoutsPage); <- allowing to access the routes in
New Routs Page
Also,
we can add a common starting point to here as below.
app.use("/admin", NewRoutsPage);
now
/admin/.. added to the all routes in the NewRoutspage
Bonus
//adding the 404 page
app.use((req, res, next) => {
res.status(404).send("<h1>No Page Found -404</h1>");
//also
can set headers-> res.setHeaders().send()
});

0 Comments