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();
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