Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
A closer look at Express's Request object.
A note on body-parser
If you are following along with the same version of Express installed in this course (v4.15.2), you should have no problems with using body-parser here. However, if you are using a more recent version of Express (v4.16.0 or higher) you will only need to use the following at the beginning of your document: app.use(express.urlencoded());
.
You can read more about this newer built-in middleware in the Express Documentation
HTML Forms
-
Sending form data (MDN)
- HTML forms (MDN general form page)
Documentation
What body-parser
Does Under the Hood
What is body-parser doing? In case you're curious, here's a little code that reads the body of an incoming request and logs it to the console. This is just a flavor of how using body-parser is making your life easier!
let bodyString = ''
req.on('data', chunk => bodyString += chunk.toString());
req.on('end', () => {
console.log(bodyString);
});
Note that even after bodyString
has been read completely, it still needs to be turned from a string into data your application can use, all of which is taken care of by body-parser.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up