Skip to content

Instantly share code, notes, and snippets.

@nodirshox
Created November 23, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nodirshox/8c5d6495753def17aa88c1125f38bc20 to your computer and use it in GitHub Desktop.
Save nodirshox/8c5d6495753def17aa88c1125f38bc20 to your computer and use it in GitHub Desktop.
Connecting MongoDB database in Node JS
// Connecting database
DB_URL = 'mongodb://localhost:27017/todo'
mongoose.connect(DB_URL, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true })
mongoose.connection.once('open', () => {
console.log('Connected to database');
}).on('error', (error) => {
console.log(`There is an error in connecting database: ${error}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment