根据this指南,我遇到了一个错误,但不确定是什么问题.
我设法到达步骤2的末尾没问题,我重新启动了服务器npm start.然后我对玉器文件a了一下,再次跑回起点,它mo吟着,而很少放入原木中.在此发布之前,我删除了整个文件夹并重新启动,但是现在npm服务器甚至都不会以express创建的基本文件开头.
当我运行时:npm install -g express和本地用户一样,我得到错误提示我以root用户身份运行.因此express是作为root用户安装的,但是npm install -g express-generator作为本地用户运行得很好.
因此,在安装了express和express生成器之后,我现在可以创建一个express项目(以本地用户身份登录,而不是以root用户,项目名称… noders身份登录):
<code>express noders </code>
现在npm install获取所有依赖项:
<code>npm install </code>
因此,从理论上讲,我现在应该能够启动节点js服务器…
<code>npm start </code>
但是结果是:
<code>Janines-MacBook-Pro:noders janinenitz$npm start
> noders@0.0.0 start /Users/janinenitz/node/noders
> node ./bin/www
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
at Server.listen (net.js:1139:5)
at Function.app.listen (/Users/janinenitz/node/noders/node_modules/express/lib/application.js:556:24)
at Object.<anonymous> (/Users/janinenitz/node/noders/bin/www:7:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
npm ERR! noders@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the noders@0.0.0 start script.
npm ERR! This is most likely a problem with the noders 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 noders
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/janinenitz/node/noders
npm ERR! node -v v0.10.35
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/janinenitz/node/noders/npm-debug.log
npm ERR! not ok code 0
</code>
和日志文件:
<code>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.35 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info prestart noders@0.0.0 6 info start noders@0.0.0 7 verbose unsafe-perm in lifecycle true 8 info noders@0.0.0 Failed to exec start script 9 error noders@0.0.0 start: `node ./bin/www` 9 error Exit status 8 10 error Failed at the noders@0.0.0 start script. 10 error This is most likely a problem with the noders 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 noders 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/janinenitz/node/noders 14 error node -v v0.10.35 15 error npm -v 1.4.28 16 error code ELIFECYCLE 17 verbose exit [ 1, true ] </code>
看完其他几篇文章后,我停止了节点服务器npm stop,然后再次开始,希望端口号没有冲突,但我得到了相同的结果.
当我以root身份运行时,得到的结果完全相同.
有人有什么想法吗?与节点一起安装的每个站点是否都占用一个端口号,并且需要删除端口或其他内容?
当运行lsof -i时,这是结果(关闭Web浏览器之后):
<code>COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME UserEvent 201 janinenitz 4u IPv4 0x45000000008e2c77 0t0 UDP *:* SystemUIS 209 janinenitz 23u IPv4 0x45000000478e706f 0t0 UDP *:53884 SystemUIS 209 janinenitz 25u IPv4 0x00000000478e6e17 0t0 UDP *:* sharingd 221 janinenitz 12u IPv4 0x450000004711d70f 0t0 UDP *:* SpotifyWe 274 janinenitz 6u IPv4 0x4500000048000000 0t0 TCP localhost:4370 (LISTEN) SpotifyWe 274 janinenitz 7u IPv4 0x456d000048b19947 0t0 TCP localhost:4380 (LISTEN) WiFiAgent 278 janinenitz 16u IPv4 0x4560000047000000 0t0 UDP *:* </code>
没有任何迹象表明在端口3000上监听(这是我之前从上面的教程获得的默认页面),我重新启动了npm,仍然得到与上述相同的结果:
<code>events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
at Server.listen (net.js:1139:5)
at Function.app.listen (/Users/janinenitz/node/noders/node_modules/express/lib/application.js:556:24)
at Object.<anonymous> (/Users/janinenitz/node/noders/bin/www:7:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
... etc etc
</code>
我还尝试告诉app.js监听随机端口号:app.listen(31001);但仍然没有喜悦:S
我使用npm install构建和安装的先前应用程序现在是否有可能与该应用程序发生冲突?是否有“卸载” nodeJs应用程序的官方方法?
干杯,
?
解决方法:
错误:侦听EADDRINUSE表示已占用端口.您是否在指定的端口上运行另一个节点应用程序或某个服务器?我的猜测是你是.
如果要终止占用端口的进程,并且正在运行linux / mac,请在终端运行:
<code>lsof -i tcp:{DESIGNATED_PORT} // Example
lsof -i tcp:8080 // Yours will need to be something like so
</code>
您将看到如下输出:
<code>COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 2940 sethkrasnianski 12u IPv4 0xdce46e6699332713 0t0 TCP *:vrpn (LISTEN) </code>
…然后抓取那个PID#并杀死-9 {PID_NUMBER}
否则,您应该只编辑app.js文件(或任何命名为入口文件的文件),然后将快速服务器分配给新的晦涩端口.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!