在terminal错误中启动Node / Express项目

我昨天晚上在做一个MEAN堆栈教程, https://thinkster.io/angulartutorial/mean-stack-tutorial/ ,一切工作正常。 然后今天上午当我尝试再次启动它时,我一直得到一个npm错误。 它说无法连接到本地主机:27017,但我昨晚连接到端口:3000,并且/ bin / www代码设置为3000。

我想这个错误可能是在package.json文件中:“start”:“node ./bin/www”,但我不确定,需要帮助。 谢谢。

Darraghs-MacBook-Pro:flapper-news dkdesign$ npm start > flapper-news@0.0.0 start /Users/dkdesign/flapper-news > node ./bin/www events.js:72 throw er; // Unhandled 'error' event ^ Error: failed to connect to [localhost:27017] at null.<anonymous> (/Users/dkdesign/flapper-news/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:549:74) at emit (events.js:106:17) at null.<anonymous> (/Users/dkdesign/flapper-news/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15) at emit (events.js:98:17) at Socket.<anonymous> (/Users/dkdesign/flapper-news/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:533:10) at Socket.emit (events.js:95:17) at net.js:440:14 at process._tickCallback (node.js:419:13) npm ERR! flapper-news@0.0.0 start: `node ./bin/www` npm ERR! Exit status 8 npm ERR! npm ERR! Failed at the flapper-news@0.0.0 start script. npm ERR! This is most likely a problem with the flapper-news package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node ./bin/www npm ERR! You can get their info via: npm ERR! npm owner ls flapper-news npm ERR! There is likely additional logging output above. npm ERR! System Darwin 14.0.0 npm ERR! command "node" "/usr/local/bin/npm" "start" npm ERR! cwd /Users/dkdesign/flapper-news npm ERR! node -v v0.10.32 npm ERR! npm -v 1.4.28 npm ERR! code ELIFECYCLE npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Users/dkdesign/flapper-news/npm-debug.log npm ERR! not ok code 0 

这是日志文件:

  0 info it worked if it ends with ok 1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ] 2 info using npm@1.4.28 3 info using node@v0.10.32 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info prestart flapper-news@0.0.0 6 info start flapper-news@0.0.0 7 verbose unsafe-perm in lifecycle true 8 info flapper-news@0.0.0 Failed to exec start script 9 error flapper-news@0.0.0 start: `node ./bin/www` 9 error Exit status 8 10 error Failed at the flapper-news@0.0.0 start script. 10 error This is most likely a problem with the flapper-news package, 10 error not with npm itself. 10 error Tell the author that this fails on your system: 10 error node ./bin/www 10 error You can get their info via: 10 error npm owner ls flapper-news 10 error There is likely additional logging output above. 11 error System Darwin 14.0.0 12 error command "node" "/usr/local/bin/npm" "start" 13 error cwd /Users/dkdesign/flapper-news 14 error node -v v0.10.32 15 error npm -v 1.4.28 16 error code ELIFECYCLE 17 verbose exit [ 1, true ] 

27017是mongodb的默认端口。 确保在运行应用程序之前,您已经启动了mongodb服务器。

尝试运行:

  killall -9 node 

要检查它是否工作:

 ps aux