Retrieve the POST query parameters using Express
New Courses Coming Soon
Join the waiting lists
Found out how to retrieve the POST query parameters using Express
POST query parameters are sent by HTTP clients for example by forms, or when performing a POST request sending data.
How can you access this data?
If the data was sent as JSON, using Content-Type: application/json
, you will use the express.json()
middleware:
const express = require('express')
const app = express()
app.use(express.json())
If the data was sent using Content-Type: application/x-www-form-urlencoded
, you will need to use the express.urlencoded()
middleware:
const express = require('express')
const app = express()
app.use(express.urlencoded({
extended: true
}))
In both cases you can access the data by referencing it from Request.body
:
app.post('/form', (req, res) => {
const name = req.body.name
})
Note: older Express versions required the use of the
body-parser
module to process POST data. This is no longer the case as of Express 4.16 (released in September 2017) and later versions.
Here is how can I help you:
- COURSES where I teach everything I know
- CODING BOOTCAMP cohort course - next edition in 2025
- THE VALLEY OF CODE your web development manual
- BOOKS 17 coding ebooks you can download for free on JS Python C PHP and lots more
- Interesting links collection
- Follow me on X