Ads by ProfitSence
Close

req.query and req.param in ExpressJS

Last Updated on Wednesday 5th Oct 2022

ExpressJS

  • ExpressJS is the default framework of NodeJS.
  • ExpressJS install
			
					npm install express

			
	
  • Import the express module.
  • Created an instance of an express application called app
			
					const express require('express');
const app = express();

// Create Route and server
// app.get parameters ('URL_address', function(){ than logic })
app.get('/', (req, res) => {
// res.send is use to display the content in browser
  res.send("Express JS server is started...");
})

			
	
  • Our callback functions for our routes receive two very special objects from Express.
  • They are provided to our function very much like the event object.
  • It was holding all the event data is passed into our event listener callbacks
  • Here, We Focus on the request Object.

The Request Object

  • The Request object, frequently abbreviated to req.
  • It contains all the data we would ever need about the actual request that came in.
  • What are you requesting? What browser are they using? Bunches of other stuff.

req.body express

  • req.body - this is where it will store any submitted form data for us.

req.params express

  • req.params - this is where special route variables are stored for us.

req.query express

  • req.query - this is where the query string data is stored.