error running server.js Node js

1

Hello, I'm doing a Node JS application and you let me know this error because if I have the JS, npm and express node installed correctly?

root@sommer-AO532h:/home/sommer/Desktop/aplicacionnode/express_example# DEBUG=express_example:* npm start
> [email protected] start /home/sommer/Desktop/aplicacionnode/express_example
> nodejs ./bin/www

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1237:14)
    at listen (net.js:1273:10)
    at Server.listen (net.js:1369:5)
    at Function.app.listen (/home/sommer/Desktop/aplicacionnode/express_example/node_modules/express/lib/application.js:531:24)
    at Object.<anonymous> (/home/sommer/Desktop/aplicacionnode/express_example/bin/www:7:18)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)

npm ERR! Linux 4.8.0-54-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: 'nodejs ./bin/www'
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'nodejs ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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!     nodejs ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs application-name
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls application-name
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/sommer/Desktop/aplicacionnode/express_example/npm-debug.log
    
asked by simon 08.06.2017 в 09:22
source

2 answers

3

The key is here:

  

Error: listen EADDRINUSE ::: 3000

That message is telling you that port 3000 is in use by another program.

You can:

  • Change the port where you run your application.

  • Find out who is using it, and stop it or change its configuration.

To see who is using it, you can do

  

sudo lsof -i: 3000

To stop it, it depends. If it is a service or daemon system, a

  

sudo service XXX stop

should be enough. To bad ones, you can also do

  

sudo kill -9 PID-DEL-PROGRAM

The PID is obtained with the previous order lsof .

This last option, kill , IS NOT RECOMMENDED unless you know very well what you are doing.

    
answered by 08.06.2017 в 09:27
1

I imagine you are using express generator or some example already done, so look for the folder bin and inside you will find a file called www open it with any editor and look for the line:

var port = normalizePort(process.env.PORT || '3000');

Modify the 3000 for another number and it will work for you. Your error is that you try to use port 3000 and as indicated by the console you already have it in use:

Error: listen EADDRINUSE :::3000

For example you can leave it in the following way:

var port = normalizePort(process.env.PORT || '4870');

If you do not have the bin folder in your main file (usually app.js) look for this line or if you do not add it:

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

And the same as before, change the 3000 to another port

    
answered by 01.08.2018 в 11:07