Monday 9 October 2017

Very new to Node/Express - help with req.body empty object issue please?

This might be a stupid question... I'm trying to get the input from a form as JSON. My form enctype is set to 'application/json' and just has one input field. The submit action goes to the proper endpoint.In my file containing my route information for this particular model I have (among a few other things):const express = require('express'); const router = express.Router(); const bodyParser = require('body-parser'); // Create application/json parser var jsonParser = bodyParser.json(); // Item Submit Post Route router.post('/add', jsonParser, (req, res) => { console.log(req.body); return; }); And the console logs an empty object '{}'. I'm trying to get the req.body.title but it doesn't appear to exist. This is my first attempt at Express/Node and everything was going smoothly up until this point. Any help would be very much appreciated.Thanks.

Submitted October 09, 2017 at 05:49PM by throwawaylayman90

No comments:

Post a Comment