Allows you to manage URLs and controllers. Known as "mini application". Router
/ => main page
/join => to make account
/login => to login
/search => to search items
/user-edit => to edit user info
/user-delete => to remove user info
/watch-vid => to watch video
/edit-vid => to edit video
/delete-video => to delete video
/user/edit
/user/delete
/videos/watch
/videos/edit
/videos/delete
/videos/comments
/videos/comments/delete
routers let you categorize the routes by subjects you working on. (routes close to the root is called global routers)
and this makes easier to understand for users and developers.
const videoRouter = express.Router(); // 1.
const handleWatchVideo = (req, res) => res.send("Video Streaming Page"); // .4
routerName.get("/watch", handleWatchVideo); // 3.
app.use("/videos", videoRouter); // 2.
When a user request for "/videos", instead of going to controller, it will go videoRouter, and look for the routes to get, which is "/watch" in here, and the handleWatchVideo controller will be executed. and forms /videos/watch address.