You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2026. It is now read-only.
// Psuedo-Codeletexpress=require('express');letapp=express();letport=process.env.PORT||8080;app.get('/',(req,res)=>{// middlewarecors.initialize();auth.verify();// final request handlerfunction(req,res){res.render('index');}});app.post('/upload',auth.isAuthenticated(),controller.upload);
Using the ExpressJS 4.0 Router
What is a Router?
Router is like a mini express application, it doesn't bring in views or settings, but provides us with routing APIs like .use, .get, .param, and .route.
Basic Routes express.Router()
// server.js// get an instance of routervarrouter=express.Router();// home page route (http://localhost:8080)router.get('/',function(req,res){res.send('im the home page!');});// about page route (http://localhost:8080/about)router.get('/about',function(req,res){res.send('im the about page!');});// apply the routes to our applicationapp.use('/',router);
Benefits of express.Router()
can create multiple express.Router()
can have a Router for our basic routes, authenticated routes, and even API routes.
allows us to make our applications more modular and flexible than ever before by creating multiple instances of the Router and apply them accordingly.