Save does not work in the Repl. Is it the Repl or the code?

Tell us what’s happening:

// define the database
var userSchema = new mongoose.Schema({
  username: String,
  _id: String,
// create the Model
var User = mongoose.model('User', userSchema);"/api/exercise/new-user", (req, res) => {
  var _id = shortid.generate();
  var username = req.body.username
  var user = new User({ username: username, _id: _id});
 .then(item => {
 res.send("item saved to database");
 .catch(err => {
 res.status(400).send("unable to save to database");

Your code so far

Your browser information:


Challenge: Exercise Tracker

Link to the challenge:

I must advise against using Repl for the APIs and Microservices Projects, if you are able to install node, express, and mongodb locally. This is because the Repl would not properly handle simple code such as the above. However, locally it works perfectly. Probably this is known by FCC anyway because when I posted for help, nobody helped me, however, all the better.

Hello there,

I suspect your issue has to do with the version of the package/packages you are using.

Also, do remember, sometimes posts just get missed by anyone able/willing to answer. Not much we can do about this; we are spread across varying timezones, with varying work schedules.

Hope this helps