Access Form Data and URL Parameters with Express

InstructorJamund Ferguson

Share this video with your friends

Send Tweet

In this lesson we'll cover how to access route params (/users/:id) and then use express.urlencoded() to give express the ability to process URL encoded form data that we'll need to add and update notes in our application. The POST body will be made available on req.body. A mention is also made about how to read query parameters from req.query.


express.urlencoded()

The extended option we pass into the urlencoded method adds the following capabilities according to the docs:

This option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The “extended” syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded

body-parser

In earlier versions of express it was encouraged to use the body-parser middleware package which is published separately from express. The common functionality is now built-in however as express.urlencoded() and express.json().


More info:

  • https://expressjs.com/en/api.html#req.params
  • https://expressjs.com/en/api.html#req.query
  • https://github.com/expressjs/body-parser