Close port with host JS

I am learning nodeJS. When I write a program that listens on a port, say 8081, and then write another program that listens on the same port, I will get this type of error message:

Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Object.<anonymous> (C:\NetBeansWorkPlace\nodeJS_Files\TutsNodeJS\static_file_server.js:36:4)
    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)

I found that the port is in use, but how can I clear the port or stop listening to the application on this port? Thank you Wbr

+4
source share
2 answers

The easiest way is to change the port number in the javascript file.

If you want to close the port just do this (mac solution) open terminal

1) sudo lsof -i:

a table will be displayed that looks for the PID in this table for your port

2) sudo kill -9 PID

+2
source

Here are your options:

1- ,

2- ,

3-

4-

4- , . , . .

0

All Articles