Error: Cannot Read Property 'close' Of Null
hello dear community im wondering myself why i get this error when i try to use mongodb and nodejs. const MongoClient = require('mongodb').MongoClient; MongoClient.connect('mongodb
Solution 1:
You might want to check if your MongoDB service is up and running on the given port. Open a Command Prompt (WindowsKey+R->cmd->OK
) and run the following command:
netstat -a | find"27017"
This should give you some output like this:
TCP 127.0.0.1:27017 <MACHINE_NAME>:0 LISTENING
If you don't see this line you need to start MongoDB or make sure it runs on the default port.
The second error "Cannot read property 'close' of null"
is simply because the connection fails so your db
variable will hold a null
value according to the docs which obviously you cannot run a close()
on. You might want to move that close()
statement inside the else
statement.
Post a Comment for "Error: Cannot Read Property 'close' Of Null"