const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager'
MongoClient.connect(connectionURL, (error, client) => {
if (error) {
return console.log('Unable to connect to database.')
}
console.log('Connection successful.')
})
I’m not getting any errors but still nothing gets printed to the console.
I’m trying to connect to the mongodb server.
2
Answers
Try getting rid of the return in the if statement.
Try using alert() instead of console.log, that’s what I always use for JS.
I hope this helps!
Try the following code snippet:
Also, refer to the get started guide: https://www.mongodb.com/docs/drivers/node/current/quick-start/connect-to-mongodb/