Node.js express NPM启动错误,退出状态为8。

4

我刚刚在亚马逊EC2上安装了Node.js,一切正常工作。然后我停止了服务器,尝试重新启动它,但现在出现了以下错误:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:904:11)
    at Server._listen2 (net.js:1042:14)
    at listen (net.js:1064:10)
    at Server.listen (net.js:1138:5)
    at Object.<anonymous> (/home/CloudChat/server.js:34:24)
    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)
    at Function.Module.runMain (module.js:497:10)
npm ERR! application-name@0.0.1 start: `node server.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the application-name@0.0.1 start script.
npm ERR! This is most likely a problem with the application-name package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls application-name
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.4.73-64.112.amzn1.x86_64
npm ERR! command "node" "/usr/local/bin/npm" "start"
npm ERR! cwd /home/CloudChat
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.4
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/CloudChat/npm-debug.log
npm ERR! not ok code 0

npm-debug.log 包含以下内容:

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

我所做的只是将app.js重命名为server.js,我也在package.json中进行了更改,但它仅在停止服务器之前起作用。

**EDIT** 

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             Stat                        e
tcp        0      0 *:webcache                  *:*                         LIST                        EN
tcp        0      0 *:ssh                       *:*                         LIST                        EN
tcp        0      0 *:hbci                      *:*                         LIST                        EN
tcp        0      0 localhost:smtp              *:*                         LIST                        EN
tcp        0    320 ip-172-31-34-214.us-wes:ssh 78-143-78-51-customer.:6639 ESTA                        BLISHED
tcp        0      0 ip-172-31-34-214.us-wes:ssh 78-143-78-51-customer.:8846 ESTA                        BLISHED
tcp        0      0 ip-172-31-34-214.us-wes:ssh 78-143-78-51-customer.:8212 ESTA                        BLISHED
tcp      429      0 ip-172-31-34-214.u:webcache 78-143-78-51-customer.:8048 CLOS                        E_WAIT
tcp        0      0 ip-172-31-34-214.us-wes:ssh 78-143-78-51-custom:fs-mgmt ESTA                        BLISHED
tcp        0      0 *:ssh                       *:*                         LIST                        EN
udp        0      0 *:bootpc                    *:*                                                     
udp        0      0 ip-172-31-34-214.us-west:ntp *:*                                                    
udp        0      0 localhost:ntp               *:*                                                     
udp        0      0 *:ntp                       *:*                                                     
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node Path
unix  2      [ ACC ]     STREAM     LISTENING     6526   /var/run/dbus/system_bu                        s_socket
unix  2      [ ACC ]     STREAM     LISTENING     5537   @/com/ubuntu/upstart
unix  12     [ ]         DGRAM                    6469   /dev/log
unix  2      [ ACC ]     SEQPACKET  LISTENING     5611   @/org/kernel/udev/udevd
unix  3      [ ]         STREAM     CONNECTED     52862
unix  3      [ ]         STREAM     CONNECTED     52861
unix  2      [ ]         DGRAM                    52858
unix  2      [ ]         DGRAM                    44741
unix  2      [ ]         DGRAM                    44722
unix  3      [ ]         STREAM     CONNECTED     41225
unix  3      [ ]         STREAM     CONNECTED     41224
unix  2      [ ]         DGRAM                    41221
unix  3      [ ]         STREAM     CONNECTED     40807
unix  3      [ ]         STREAM     CONNECTED     40806
unix  2      [ ]         DGRAM                    40803
unix  2      [ ]         DGRAM                    40121
unix  3      [ ]         STREAM     CONNECTED     38240
unix  3      [ ]         STREAM     CONNECTED     38239
unix  2      [ ]         DGRAM                    38236
unix  2      [ ]         DGRAM                    11231
unix  2      [ ]         DGRAM                    7465
unix  2      [ ]         DGRAM                    7446
unix  2      [ ]         DGRAM                    7428
unix  2      [ ]         DGRAM                    7347
unix  3      [ ]         STREAM     CONNECTED     6535   /var/run/dbus/system_bu                        s_socket
unix  3      [ ]         STREAM     CONNECTED     6534
unix  3      [ ]         STREAM     CONNECTED     6530
unix  3      [ ]         STREAM     CONNECTED     6529
unix  3      [ ]         DGRAM                    5627
unix  3      [ ]         DGRAM                    5626
[root@ip-172-31-34-214 CloudChat]#

仍然收到错误。 - user2559108
3个回答

11

问题是该端口已被占用,或者您没有权限绑定该端口。

尝试更改HTTP服务器的监听端口或使用sudo node app.js以root身份运行服务器。


我已经尝试过了,但端口被占用可能是问题所在,感谢提供信息。 - user2559108
1
你检查过使用该端口的程序了吗?netstat -a - Pedro Nasser
我将应用程序设置为监听端口8080,该端口重定向到端口80,该端口似乎未被使用,我已将输出添加到问题中。 - user2559108

4

如果您遇到与我相同的情况,以下是如何关闭Express:

ps aux | grep node
Find the process ID (second from the left):
kill -9 PRCOCESS_ID

给出进程ID # lsof -P | grep ':3000' | awk '{print $2}' - Wade Anderson

0

使用Express 4时,启动脚本位于./bin/www

如果你遇到这个错误(就像我一样),只需编辑并替换它

app.set('port', process.env.PORT || 5000);

app.set('port', process.env.PORT || YOUR_PORT_NUMBER);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接