How to filter path of routes in Express.js ? Last Updated : 28 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Express.js is a powerful framework for node.js. One of the main advantages of this framework is defining different routes or middleware to handle the client's different incoming requests. In this article, we will be discussing how to filter the paths of routes using the express.js in node.js. The app.use() method is used to handle different to filter the request for particular routes in node.js This function is used to mount the specified middleware function(s) at the path which is being specified. It is mostly used to set up middleware for your application. Syntax: app.use(path, callback)Parameters: This method takes the following two parameters: path: It is the path for which the middleware function is being called. It can be a string representing a path or path pattern or a regular expression pattern to match the paths.callback: It is a middleware function or a series/array of middleware functions. Â Installing Module: Install the required module using the following command. npm install expressProject structure: It will look like this. Note: Home.js and login.js files are present in the routes folder. Home.js // Importing express module const express = require("express") const router = express.Router() // Handling request using router router.get("/home", (req, res, next) => { res.send("This is the homepage request") }) // Exporting the router module.exports = router login.js // Importing the module const express = require("express") // Creating express Router const router = express.Router() // Handling login request router.get("/login", (req, res, next) => { res.send("This is the login request") }) // Exporting the router module.exports = router index.js // Requiring module const express = require("express") // Importing all the routes const homeroute = require("./routes/Home.js") const loginroute = require("./routes/login") // Creating express server const app = express() // Filtering the routes path app.use("/", homeroute) app.use("/", loginroute) // Server setup app.listen((3000), () => { console.log("Server is Running") }) Run index.js file using below command: node index.jsOutput: Now open your browser and go to http://localhost:3000/home, you will see the following output: Comment More infoAdvertise with us Next Article How to filter path of routes in Express.js ? Z zack_aayush Follow Improve Article Tags : Web Technologies Node.js Express.js NodeJS-Questions Similar Reads How To Handle Route Parameters in Express? Route parameters in ExpressJS capture dynamic values from URLs, like /users/:userId. These values are accessible in your route handler via req.params, enabling dynamic content generation. This allows for creating reusable routes that handle various inputs with a single pattern.JavaScriptapp.get('/us 4 min read How do you handle nested routes in Express.js? In this article we are going to learn that how can we setup nested routes in Express JS. Nested routes are the routes that are defined within other routes. This is used to organize your code.We are going to implement the nested routes using the below given two approaches.Table of ContentUsing Expres 2 min read How to use get parameter in Express.js ? Express Js is a web application framework on top of Node.js web server functionality that reduces the complexity of creating a web server. Express provides routing services i.e., how an application endpoint responds based on the requested route and the HTTP request method (GET, POST, PUT, DELETE, UP 2 min read How to Setup Regex for ExpressJS Router URL in Node.js ? ExpressJS Router is a class that acts as a middleware to provide route handling or determining how an application responds to a client requests, of various HTTP methods, to a particular URI.ApproachSetting up regex for Express.js router URLs in Node.js involves defining custom patterns using regular 3 min read How to handle redirects in Express JS? Express JS uses redirects to send users from one URL to another. This can be done for various reasons, such as handling outdated URLs or guiding users through a process. In ExpressJS, you define routes and use them to direct users to the desired URL. It's a way to keep your application organized and 2 min read Like