how to get the value from requestpost via nodejs
To get the value from request.post in Node.js, you can use the body-parser middleware. Here's an example:
- First, install body-parser using npm:
npm install body-parser --save
- In your Node.js app, require the body-parser module:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
- Then, in your route handler, you can access the values from the request body using req.body:
app.post('/api/users', (req, res) => {
const name = req.body.name;
const email = req.body.email;
const password = req.body.password;
// Do something with the values...
});
Note: Make sure to include the "Content-Type" header in your request with a value of "application/x-www-form-urlencoded" or "application/json" depending on the format of your request body.
原文地址: http://www.cveoy.top/t/topic/JqO 著作权归作者所有。请勿转载和采集!