ExpressJS - throw er Unhandled error event

前端 未结 30 1910
囚心锁ツ
囚心锁ツ 2020-12-12 09:30

I created expressjs application using the following commands:

express -e folderName
npm install ejs --save
npm install

When I run the appli

相关标签:
30条回答
  • 2020-12-12 10:12

    I fixed the bug by changing the port which was

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

    and changed to:

    app.set('port', process.env.PORT || 8080);<br>
    
    0 讨论(0)
  • 2020-12-12 10:13

    this means your file is running now. just enter below code and try again:

    sudo pkill node
    
    0 讨论(0)
  • 2020-12-12 10:14

    Reason for this error

    Some other process is already running on the port you have specified

    Simple and Quick solution

    On Linux OS, For example you have specified 3000 as the port

    • Open the terminal and run lsof -i :3000. If any process is already running on port 3000 then you will see this printing on the console

    COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    node    16615 aegon   13u  IPv6 183768      0t0  TCP *:3000 (LISTEN)

    • Copy the PID (process ID) from the output

    • Run sudo kill -9 16615 (you have to put PID after -9)

    • Start the server again
    0 讨论(0)
  • 2020-12-12 10:15

    If you want to use the same port number then type kill % in the terminal, which kills the current background process and frees up the port for further usage.

    0 讨论(0)
  • 2020-12-12 10:16

    In my case the issue was caused by forgetting to call next() in an expressjs `use' method call.

    If the current middleware does not end the request-response cycle, it must call next() to pass control to the next middleware, otherwise the request will be left hanging.

    http://expressjs.com/guide/using-middleware.html

    0 讨论(0)
  • 2020-12-12 10:17

    This is because the port you are using to run the script is already in use. You have to stop all other nodes which are using that post. for that, you can check all node by

    ps -e
    

    OR for node process only use ps -ef | grep node This will give you the list of all node process with id

    to Kill all node process

    sudo killall -9 node
    

    Or for the specific id sudo kill -9 id

    0 讨论(0)
提交回复
热议问题