banner



How To Stop Node Server Windows

Cover image for How to kill a node process

Davide de Paolis

Stop Node Server How to kill a node process

While working on a full-stack application information technology might happen that yous end up with a bunch of node processes running at the same time.
It could be some automation script or a script that watches and executes your unit-tests while y'all code/TDD.
Most likely it is Webpack running and serving your frontend on localhost and the node app that serves the Residual API your frontend is connecting to. In both cases these processes would occupy a specific port.

For case, our current React App is served on localhost:3000 and the backend runs on localhost:3001 via serverless offline.

Normally yous would start those processes via the command line with something like:

              npm run react-scripts start                          

Enter fullscreen mode Exit fullscreen manner

or

              sls offline start --port 3001                          

Enter fullscreen mode Exit fullscreen mode

When y'all are running those, you can quickly shut them down with

                              <Ctrl> + C                          

Enter fullscreen mode Go out fullscreen mode

If you started them via a Debug Configuration in Visual Studio Lawmaking or IntelliJ IDEA you can stop the procedure clicking the Stop button.

stop debugging process

Until here no problem. Sometimes though it happens that you started some process then despite closing the IDE or the Terminal they yet hang there somewhere, and when you try to run them again, so yous become errors that the port is occupied.

I don't know why or how that happens, but every now and and then ( weeks or months) I find myself googling for the right command to use ( i tend to forget speedily stuff that I don't use often - and that I tin can google under 20 seconds ). Therefore I will drib it here, it might be useful for someone else too!

              ps -ef | grep node # or  ps aux | grep node                          

Enter fullscreen mode Exit fullscreen mode

This commands will print all the node procedure running, information technology might be disruptive at start since you might have other stuff that is non related to the projection you lot are working on (similar Slack or Postman).
Just find the node process pointing to your script or js file and notation down the process ID (second value from the left)

node processes running

If yous observe yourself with a wall of text considering you lot accept many processes running, then you could search the processes opened past port ( like ordinarily when I start a react application is on port 3000 while its backend is on port 3001:

              lsof -i :3001                          

Enter fullscreen mode Exit fullscreen style

Once you have your process and its ID..

then just kill it without mercy!

              kill -9 PROCESS_ID                          

Enter fullscreen mode Exit fullscreen mode

Promise it helps

Source: https://dev.to/dvddpl/how-to-kill-a-node-process-5d13

Posted by: rezawhoored.blogspot.com

0 Response to "How To Stop Node Server Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel