Node.js express POST 404ing
If you are posting to / as your log is saying that you are "POST / 404 5ms", you need to change the following line:
app.get('/', routes.index);
to
app.all('/', routes.index);
This will allow a GET or POST to that route. You can also just use app.post()
if you are only posting to that route. Hope this helps.
Docs here: http://expressjs.com/api.html#app.all
Make sure that 'form.attr("action")' is getting the proper URL. It seems that your form is posting to the index page rather than to '/test'. Maybe that should be changed to $('form').attr("action")
For me the problem was that I had my
app.post('/test', jsonParser, function (req, res) { console.log(req); res.send('Ok');});
below this part added by express-generator to my app.js
// catch 404 and forward to error handlerapp.use(function(req, res, next) { next(createError(404));});
By changing the order in the file I resolved this problem.