//The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
//In this documentation and by convention, the object is always referred to as res (and the HTTP request is req) but its actual name is determined by the parameters to the callback function in which you’re working.
For example:
app.get('/user/:id', function (req, res) {
res.send('user ' + req.params.id)
})
var http = require('http');
var options = {
host: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
// write data to request body
req.write('data
');
req.write('data
');
req.end();
//The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
//In this documentation and by convention, the object is always referred to as res (and the HTTP request is req) but its actual name is determined by the parameters to the callback function in which you’re working.
For example:
app.get('/user/:id', function (req, res) {
res.send('user ' + req.params.id)
})
yourproject/views/index.ejs
<html>
<head><title></title></head>
<body>
<form action="/" method="POST">
<input name="abc" />
<input type="submit" value="submit"/>
</form>
</body>
</html>
yourproject/routers/index.js
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.post("/", async function(Req, res, next)
{
res.send(req.body.abc)
});
module.exports = router;
npm install request@2.81.0