How To Install Express Gate
Express.js req.body Property
The req.body property contains primal-value pairs of data submitted in the request body. Past default, it is undefined and is populated when y'all use a middleware chosen body-parsing such as express.urlencoded() or limited.json().
Syntax:
req.body
Parameter: No parameters.
Return Value: Object
Installation of express module:
- You lot can visit the link to Install express module. You can install this package by using this command.
npm install express
- Subsequently installing the limited module, you lot tin can cheque your limited version in control prompt using the command.
npm version express
- After that, you tin only create a binder and add a file for example, index.js. To run this file yous need to run the post-obit command.
node index.js
Example 1: Filename: index.js
var express = require( 'express' );
var app = express();
var PORT = 3000;
app.use(limited.json());
app.use(limited.urlencoded({ extended: true }));
app.post( '/profile' , function (req, res) {
console.log(req.body);
res.transport();
});
app.heed(PORT, office (err){
if (err) console.log(err);
console.log( "Server listening on PORT" , PORT);
});
Steps to run the program:
- The project structure will wait similar this:
- Make certain yous accept installed limited module using the following command:
npm install express
- Run alphabetize.js file using below command:
node index.js
Output:
Server listening on PORT 3000
- Now brand Mail service request to http://localhost:3000/profile with following trunk:
{ "title":"Greetings from GeeksforGeeks" }Now you lot tin can see the following output on your panel:
Server listening on PORT 3000 { title: 'Greetings from GeeksforGeeks' }
Case 2: Filename: index.js
var express = crave( 'express' );
var app = limited();
var PORT = 3000;
app.use(limited.json());
app.use(express.urlencoded({ extended: true }));
app.post( '/signup' , function (req, res) {
var information = req.body;
console.log( "Name: " , data.proper name);
console.log( "Age: " , data.age);
console.log( "Gender: " , information.gender);
res.transport();
});
app.listen(PORT, function (err){
if (err) console.log(err);
console.log( "Server listening on PORT" , PORT);
});
Run index.js file using below command:
node index.js
At present make a POST asking to http://localhost:3000/signup with the following request torso:
{ "name": "Gourav", "age": 13, "gender":"Male" } Output: At present you will see the following output on your console screen:
Server listening on PORT 3000 Proper name: Gourav Age: 13 Gender: Male
Reference: https://expressjs.com/en/4x/api.html#req.body
Source: https://www.geeksforgeeks.org/express-js-req-body-property/
Posted by: rojastingettere.blogspot.com

0 Response to "How To Install Express Gate"
Post a Comment