Node JS Express Route with Parameters Example
Hi Dev,
Now, let's see article of node js express route with parameters. let’s discuss express route parameters example. This article goes in detail on express route url parameters. We will look at examples of how to create routes with parameters in nodejs.
In this example, I will give you a very simple example of get route with params and show you output as well. so let's see step by step simple routing with node express example.
Create Node Project:
you can run bellow command to create node app.
mkdir my-request-app
cd my-request-app
npm init
Install Express:
npm install express
Create Server.js File
let's create server.js file with get and post route.
server.js
var express = require('express');
var app = express();
app.get('/user/:id', function(request, response){
var id = request.params.id;
response.send("User id is " + id);
});
app.listen(3000, () => console.log(`App listening on port 3000`))
Output:
localhost:3000/user/5
User id is 5
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Generate 4,6,8,10 Digit Random number in Node JS?
- Node JS Read and Write Json File Example
- Node JS Find and Update Object in Array Example
- How to Get Data from Json File in Node JS?
- How to Remove Element from Array in Node JS?
- How to Push Element in Array in Node JS?
- How to use Underscore JS in Node JS App?
- Node JS Sort Array of Objects by Value Example
- Node JS Foreach Loop Array Example
- How to Create and Use .env File in Node JS?
- Axios HTTP requests in Node JS Example
- Node JS Http Request with Headers Example