Express requests have a `params` object that contains route parameters, as well as a `query` object that contains query parameters. Here's what you need to know.
In Express, route parameters are values derived from portions of the URL that start with :
. The the req.params
property is where Express stores the values of the named sections in the URL.
const app = require('express')();
// `:userId` is a route parameter. Express will capture whatever
// string comes after `/user/` in the URL and store it in
// `req.params.userId`
app.get('/user/:userId', (req, res) => {
req.params; // { userId: '42' }
res.json(req.params);
});
const server = await app.listen(3000);
// Demo of making a request to the server
const axios = require('axios');
const res = await axios.get('http://localhost:3000/user/42');
res.data; // { userId: '42' }
Route parameters are also known as URL parameters.
Node.js Express PDF to HTML Files Converter Web Application Online in Javascript 2020
We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.
Node.js Express Text Repeater Generator Online Tool in Javascript Full Tutorial 2020
Node.js Express Youtube Video URL Timestamp Link Generator in Javascript Full Project 2020
Node.js Express Minify JSON Online Converter Full Web App Deployed to Live Website 2020