Ramzi
Ramzi

Reputation: 91

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

if i reinstall mongodb,the code works fine. i wanted an permenant solution

c[error:MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017 ]

const mongoClient=require("mongodb").MongoClient
const state={
    db:null
}

module.exports.connect=function(done){
    const url="mongodb://localhost:27017"
    const dbname="r-kart"
    mongoClient.connect(url,(err,data)=>{
        if(err) return done(err)
        state.db=data.db(dbname)
        done()
    })
}
module.exports.get=function(){
    return state.db
}

Upvotes: 1

Views: 1827

Answers (1)

Abhishek Thakur
Abhishek Thakur

Reputation: 1

You can try: Go to the control panel and select admins. tools. click on "Services" and a list will appear. look of MongoDB and right click and click on start.

May be this work for you

Upvotes: 0

Related Questions