NodeJs Tutorials
- NodeJs
- Install NodeJs
- Why use NodeJs
- NodeJs Process Model
- create First Application
- Run NodeJs Application
- Node.js Console
- Node.Js Modules
- URL Modules
- node.js Callback
- Node.js Events
- Upload Files
- Upload single & Multiple Files
- NodeJs File System
- NodeJs Email
- Debugging NodeJs
- .ENV
- NodeJs Mysql
- Helpers
- encription and decription in nodeJs
- Query string
- Date & Time
- Express Js
- Template Engine with Express
- MVC Pattern in Node.Js
- list of NPM Module
- Middleware
- Body Parser
- Render
- Nodemon module
- Morgan module
- Flash Message in ExpressJs
- Session
- Session store in database
- Cookies
- Helmet
- Multer
- Router: How To Use Routing In Node.Js
- App.Js
- express.json() and express.urlencoded()
- REST APIs in NodeJs
- Gloabal Objects
- Submit Form Data
- How to get Post Data in Node.js
- How to Get URL Parameters in Node.js
- How to create Node Project
- How to Insert Form Data Into the MySql Table Using Node.js
- How to fetch Data from MySQL database table using Node.js
- CRUD Example
- Await and Async
- Promises
- Login Example
- Password Encription
- How to validate Form (Form Validation) in Node.Js?
- Registration & Login form usingn Node.Js & MySql?
- Forgot & Reset Password
- File Upload in Node.Js with ExpressJs
- Resize Image Before Upload using Multer Sharp
- Upload multiple file using node.js with multer module
- Upload file using node.js with multer module
- Client IP Address
- REST API Downloading File in NodeJs
- Export and Download CSV From MySQL Database
- CRUD REST API
- CRUD REST API Example 2
- Enable HTTPS using Node
- How to send EMAIL using NodeJs?
- Dynamic dependent dropdown using NodeJs?
- Autocomplete Search
- Get and Send Data From Ajax Request
- Get and Post Data using Ajax
- Passport Authentication
- Node Js Data type
- Node Js Error
- Node Js Array Function
- Node Js String Function
- Puppeter Module
How to Get URL Parameters in Node.js
URL Module :-
we can get URL parameters in Node.js by importing the url module.
The get() method of URLSearchParams object gets the value of the given url parameter.
File Name :
const url = require('url');
// new URL object
const current_url = new URL('http://ittutorial.in/controller/method?id=07&name=sana');
// get access to URLSearchParams object
const params = current_url.searchParams;
// get url parameters
const id = params.get('id');
const name = params.get('name');
console.log(id);
console.log(name);
Getting Values of Multi-Valued Parameters
The getAll() method of URLSearchParams object returns an array of values of the given parameter.
File Name :
const url = require('url');
const current_url = new URL('http://ittutorial.in/controller/method?id=07&name=sana');
const search_params = current_url.searchParams;
const params = search_params.getAll('tags');
// [ "07", "sana" ]
console.log(params );
Checking If Parameter Present or not :-
The has() method checks given parameter exists in the url.
File Name :
const url = require('url');
const current_url = new URL('http://ittutorial.in/controller/method?id=07&name=sana');
const search_params = current_url.searchParams;
// true
if(search_params.has('id')) {
//
}
// false
if(search_params.has('type')) {
//
}
req.query
File Name :
var id = req.query.id; // $_GET["id"]
######################## OR ######################
var url = require('url');
var params = url.parse(request.url, true);
var query = params.query;
File Name :
app.get('/user/:id', function(req, res) {
res.send('user' + req.params.id);
});
File Name :