madhums / node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)

Home Page:https://nodejs-express-demo.fly.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'on' of undefined in server.js file

lumos102 opened this issue · comments

when I run npm start after cp .env.example .env, it shows: TypeError: Cannot read property 'on' of undefined in server.js file(line 43)

Ran into the same error. I guess mongoose API has changed, so the connection property is now in the mongoose object. Essentially, this is how the connect() function in server.js should look like now

function connect () {
  var options = { server: { socketOptions: { keepAlive: 1 } } };
  mongoose.connect(config.db, options);
  return mongoose.connection;
}

Hi, sorry for the late response. This should be fixed now. Also note that keepAlive is not nested anymore. 642fba2#diff-78c12f5adc1848d13b1c6f07055d996e