Why do we use Body-parser in Node.js?

0 votes
When we can get the request without body-parser in Node.js using express .get() method. why do we need it?
May 20 in Others by ArchanaNagur
• 1,910 points

retagged May 22 by Kalgi 22 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

For understanding this first you need to know the structure of a Request

Where URL - Is the resources you want to access to like example- http://example.com

Method- what you want the server to do, like do you want the server to POST, PUT, GET or DELETE

Header- Contains the meta-data of your request

Body- Contains the information which is required to process the request.

Suppose if you want to insert a data into the database, you have to first get the data from the user (Which is present in the body of your HTTP request) and then insert it into your database through your application.

So what exactly your express .get() method does is that it is used to get the raw data. But if you want only the data which is present in the body of your request then you have to parse using body-parser.

const bodyParser = require('body-parser');

// support parsing of application/json type post data

//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));

answered May 20 by sunshine
• 900 points

Related Questions In Others

+1 vote
1 answer

Why is the result distorted when we use threads?

A thread is basically a part of ...READ MORE

answered Jun 6 in Others by Nisa
• 830 points
0 votes
1 answer

How do I start studying Node.JS to create a restful API?

Node.js is an open source server environment ...READ MORE

answered Jun 10 in Others by ArchanaNagur
• 1,910 points
0 votes
2 answers

How do neural networks used in AI and deep learning learn?

A neural network is a hardware or software ...READ MORE

answered Apr 8 in Others by SA
• 1,030 points
0 votes
0 answers

How to communicate gRPC example working with Node.js?

Hi Guys, I am working as a Node.js ...READ MORE

Dec 5, 2018 in Others by camillelola
• 140 points
0 votes
0 answers

Can we write AES enryption in Javascript and Decryption in Java using a static SALT and IV

I'm working on AES encryption I want to ...READ MORE

Jun 3 in Others by Eighteen
• 120 points
0 votes
1 answer

how to safely deploy npm install without it causing inconsistencies?

The recent versions on npm generates a ...READ MORE

answered Apr 11, 2018 in DevOps on Cloud by DareDev
• 6,710 points
0 votes
1 answer

Unable to request channel creation using Rest Api

I'd recommend taking a look at the ordering ...READ MORE

answered Jul 16, 2018 in Blockchain by Perry
• 16,450 points
0 votes
1 answer

Why and when to use Node.js?

The major reason why they are going ...READ MORE

answered Jun 14 in Others by sunshine
• 900 points

edited Jun 14 by sunshine 17 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.