express urlencoded code example
Example 1: urlencoded json express
var express = require('express')
var app = express()
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.post('/profile', function (req, res, next) {
console.log(req.body)
res.json(req.body)
})
Example 2: express request path
// GET 'http://www.example.com/admin/new?a=b'
app.get('/admin', (req, res, next) => {
req.originalUrl; // '/admin/new?a=b' (full path with query string)
req.baseUrl; // '/admin'
req.path; // '/new'
req.baseUrl + req.path; // '/admin/new' (full path without query string)
});
Example 3: node js http request express
npm install request@2.81.0