json - Express is sending an object with an object inside -
i have express server hooked mongoose db (my terminology might not correct, have started learning express). when access /admins (route?) receive object json object inside.
am sending incorrectly?
var userschema = new schema({ firstname: {type: string, trim: true}, lastname: {type: string, trim: true}, classyear: number, email: {type: string, unique: true, sparse: true, trim: true}, phone: {type: string, unique: true, sparse: true}, phoneprovider: {type: string, trim: true}, isadmin: {type: boolean, index: true}, issuperadmin: {type: boolean, index: true}, hash: string, companyname: {type: string, trim: true}, interests: [string], }, { toobject: { getters: true }, timestamps: { createdat: 'createddate', updatedat: 'updateddate' } } );
part of admins.js
exports.createadmin = function(req, res, next) { if (typeof req.body.email !== 'string') return res.status(400).send('missing email'); if (typeof req.body.password !== 'string' && typeof req.body.hash !== 'string') return res.status(400).send('missing password'); if (typeof req.body.companyname !== 'string') return res.status(400).send('missing companyname');
req.body.email returns undefined. json being received like:
{ '{\n\temail:'an@email.com'}': ''}
here's route /admins:
app.post('/admins', admins.createadmin);
here's middleware:
app.param('id', function(req, res, next, id) { if (!id.match(/^[0-9a-fa-f]{24}$/)) return res.status(400).send('invalid id'); next(); });
Comments
Post a Comment