Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have my MongoDB server running on localhost:27017, and while I can usually run my Node.js app fine, when I disconnect from the internet Mongoose throws the error

Error: failed to connect to [localhost:27017]

Note that I can still connect to the MongoDB server from the Mongo shell client. Also, if I start up my app first and then lose internet connection, my app can access the database fine offline. So why can't it start up without internet?

EDIT: here is the error in full

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (<My App>
ode_modulesmongoose
node_modulesmongodblibmongodbconnectionserver.js:555:74)
    at emit (events.js:118:17)
    at null.<anonymous> (<My App>
ode_modulesmongoose
node_modulesmongodblibmongodbconnectionconnection_pool.js:156:15)
    at emit (events.js:110:17)
    at Socket.<anonymous> (<My App>
ode_modulesmongoos
e
ode_modulesmongodblibmongodbconnectionconnection.js:534:10)
    at Socket.emit (events.js:107:17)
    at net.js:923:16
    at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...

Edit: wording

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
466 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use 127.0.0.1 instead of localhost. By turning off your wifi interface the OS is no longer able to resolve localhost.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...