I created expressjs application using the following commands:
express -e folderName
npm install ejs --save
npm install
When I run the appli
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>
this means your file is running now. just enter below code and try again:
sudo pkill node
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
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)
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.
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
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