error when starting the server with grunt or node server

François Romain picture François Romain · Jan 4, 2014 · Viewed 9.6k times · Source

I am trying to use the mean stack as described here : http://mean.io/

after install, when making "grunt", there is an error :

debugger listening on port 5858
4 Jan 01:47:40 - [nodemon] reading ignore list
Express app started on port 3000

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
    at EventEmitter.emit (events.js:106:17)
    at null.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:441:14
    at process._tickCallback (node.js:415:13)
4 Jan 01:47:40 - [nodemon] app crashed - waiting for file changes before starting...

I tried the troubleshooting as specified on the site : Updating Grunt, bower and cleaning npm and bower caches worked well. but updating npm gives an error too:

npm ERR! error rolling back Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm

This looks like a conflict between homebrew and npm. but anyway i have version 1.3.21 installed.

There is the same error when i am trying node server.

do you have an idea on what i can do to make the server work ?

Answer

bredikhin picture bredikhin · Jan 4, 2014

It may be too easy, but seems like your MongoDB server is not actually running. After having installed Mongo (on your Mac, I assume?), you have to open a Terminal window/tab, run mongod and leave it running (or use screen, etc.). You can try to access MongoDB CLI by typing mongo to make sure the server is running.