Express.js express.urlencoded() Function
Improve Article
Save Article
Like Article
- Difficulty Level : Basic
- Last Updated : 17 Jan, 2023
Improve Article
Save Article
The express.urlencoded() function is a built-in middleware function in Express. It parses incoming requests with urlencoded payloads and is based on body-parser.
Syntax:
Parameter: The options parameter contains various property like extended, inflate, limit, verify etc.
Return Value: It returns an Object.
Installation of express module:
- You can visit the link to Install express module. You can install this package by using this command.
- After installing the express module, you can check your express version in command prompt using the command.
- After that, you can just create a folder and add a file for example, index.js. To run this file you need to run the following command.
Example 1: Filename: index.js
javascript
var npm install express0npm install express1npm install express2
var npm install express4
var npm install express6
npm install express7npm install express8npm install express9
npm version express0
npm version express1npm version express2npm version express3npm version express4 npm version express5
npm version express6npm version express7
npm version express6npm version express9
node index.js0
node index.js1npm version express4node index.js3
npm version express6node index.js5 node index.js6
npm version express6node index.js8node index.js9npm install express0
node index.js0
Steps to run the program:
- The project structure will look like this:
- Make sure you have installed express module using the following command:
- Run index.js file using below command:
Output:
- Now make a POST request to //localhost:3000/ with header set to ‘content-type: application/x-www-form-urlencoded’ and body {“name”:”GeeksforGeeks”}, then you will see the following output on your console:
Example 2: Filename: index.js
javascript
var npm install express0npm install express1npm install express2
var npm install express4
var npm install express6
node index.js0
node index.js1
npm version express0
npm version express1npm version express2npm version express3npm version express4 npm version express5
npm version express6npm version express7
npm version express6npm version express9
node index.js0
node index.js1npm version express4node index.js3
npm version express6node index.js5 node index.js6
npm version express6node index.js8node index.js9npm install express0
node index.js0
Run index.js file using below command:
Now make a POST request to //localhost:3000/ with header set to ‘content-type: application/x-www-form-urlencoded’ and body {“title”:”GeeksforGeeks”}, then you will see the following output on your console:
Reference:
My Personal Notes arrow_drop_up
Save