Created
November 23, 2020 16:20
-
-
Save nodirshox/8c5d6495753def17aa88c1125f38bc20 to your computer and use it in GitHub Desktop.
Connecting MongoDB database in Node JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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