Istiak Morsalin
Istiak Morsalin

Reputation: 11159

Can not Connect to Node Client. Error: connect ECONNREFUSED 127.0.0.1:27017

I am writing this line of code to connect to mongodb via mongoose.

var db=mongoose.connect('mongodb://localhost/bookapi');

But this is showing this error in command prompt.

Error: connect ECONNREFUSED 127.0.0.1:27017
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

Help Please.

Upvotes: 0

Views: 4038

Answers (3)

Saurabh Ariyan
Saurabh Ariyan

Reputation: 863

This error primarily means that the node server cannot connect to the mongodb instance.

Reasons:

  • Is the mongod service running?

  • If the mongo db is not on localhost, check internet connectivity, firewall permissions.

Upvotes: 0

Istiak Morsalin
Istiak Morsalin

Reputation: 11159

I just have to Run mongod from cmd. That was creating the error.

Upvotes: 1

Majeed Siddiqui
Majeed Siddiqui

Reputation: 548

  1. Try connecting to mongodb://localhost:27017/bookapi

  2. Check if mongoose is installed and running. if you are using windows please refer this https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-windows/ for adding mongodb as a service.

Upvotes: 0

Related Questions