Setting up a GET endpoint in Express is straight forward. However, creating a POST endpoint took a little research as the data posted to the endpoint isn't readily available without some intervention.
As of Express 4 body-parser is no longer included in express core.So we'll now need to include the body-parser middleware.
npm install body-parser --save
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.post('/user/login', function(req, res) {
console.log(req,body);
console.log(req.body.username +' '+ req.body.password);
});
I have seen the suggestion to use the express methods before:
app.use(express.urlencoded());
app.use(express.json());
That results in an error saying that these are no longer part of express and must be installed separately. Any suggestions on how exactly to do that? All the help text I find seems to reference previous versions, installing connect, etc.
Thanks
Thanks, fixed the typo. It would be great to collaborate with others on web related projects