tonoslfx
tonoslfx

Reputation: 3442

Node.JS event error

i have just moved server to Amazon EC2.

Node.JS was working fine before but since moved, it gives me an event error which im not really sure whats going on.

i run command netstat -nlp to see if the ports number are opened.

the ports number are opened (8080 and 8181).

its giving an error on line 89:7 which the following:

https.listen(port, function(){
    console.log('HTTPS Server listening at port: ' + port);
});

enter image description here

Upvotes: 0

Views: 65

Answers (1)

Andy
Andy

Reputation: 17771

EADDRINUSE means "error - address in use". You need to stop the service already listening on that address (read: IP and port combination). You can discover the pid and name of that service with lsof:

sudo lsof -Pan -i tcp | grep -E '(8080|8181)' 

i.e. on my local machine:

$ sudo lsof -Pan -i tcp | grep -E '(51235)'
java      12413   andy  669u  IPv4 1088377      0t0  TCP *:51235 (LISTEN)

The pid (process ID) is the second number - in this case, 12413. This can be used to terminate the process.

Use kill 12413 to terminate that process. Another lsof shows there's nothing listening on that port, as it's been killed:

$ sudo lsof -Pan -i tcp | grep -E '(51235)'
<nothing here>
$

It may be that you've already got another service running (HTTP proxies tend to listen on 8080), or possibly another version of your same app. You may have to decide whether to use different ports or move the current service if there's a proxy running there.

Upvotes: 2

Related Questions