'req.body.username' and 'req.body.password' are undefined [duplicate]
//body-parserapp.use(function(req, res, next) app.use(bodyParser.urlencoded({extended:true}));
The above first line of code is incomplete and unnecessary. To correctly initialize body parser you can simply do the following as pointed out in the documentation.
// parse application/x-www-form-urlencodedapp.use(bodyParser.urlencoded({ extended: false }))// parse application/jsonapp.use(bodyParser.json())
You're missing the main body-parser directive:
app.use(bodyParser.json())