1

Am merging 2 different applications one is an authentification app and the other is a todo app where user input data and the app displays it. The two work fine seperately. when i merged them there is a parse error on the second app; I think i got the issue. the authentification app uses app.use(bodyParser.json()); and the second one uses app.use(bodyParser()); I think there is a conflict but i dont know how to solve it can you help

here is my api

var Meetup = require('./models/meetup');



module.exports.create = function (req, res) {
  var meetup = new Meetup(req.body);
  console.log(req.body);
  meetup.save(function (err, result) {
    console.log(result);
    res.json(result);
  });
}

module.exports.list = function (req, res) {
  Meetup.find({}, function (err, results) {
    res.json(results);
  });
}

console.log(req.body) displays undefined. console.log(result) displays { __v: 0, _id: 583464c837cb810e045b1825 } while it should display { __v: 0,name:'text input' _id: 583464c837cb810e045b1825 }

here is my schema model :

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var Meetup = new Schema({
  name: String,
  text:String,

});


module.exports = mongoose.model('Meetup', Meetup);

1 Answer 1

1

The bodyParser() constructor is deprecated.

You should use this instead:

app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.