npm-watch icon indicating copy to clipboard operation
npm-watch copied to clipboard

npm-watch does not stop the last server before running the updated one

Open mlarabi opened this issue 3 years ago • 5 comments

I first thought that it was a nodemon issue but it seems that it is not the case. Basically when the server restart, the port is still used by the last running server.

Here is a repository so you can reproduce the error: https://github.com/mlarabi/nodemon-restart-issue

https://user-images.githubusercontent.com/75162562/125233505-fcfd2e00-e2de-11eb-928f-33a6bf7e7920.mp4

It does not seem to be a nodemon issue because when I use nodemon directly to the entry point, it works fine.

https://user-images.githubusercontent.com/75162562/125233567-25852800-e2df-11eb-8f72-c1bcb32c020b.mp4

mlarabi avatar Jul 12 '21 05:07 mlarabi

I got same problem, can we somehow kill previous process before running new one?

abahrisd avatar Jul 28 '21 07:07 abahrisd

@abahrisd I use kill-port for now until the bug is fixed. Just before running the server I wrote killPort(3000, 'tcp').then(() => server.listen(3000, () => console.log("hello world"))). Be careful into not sending this code in prod.

mlarabi avatar Aug 05 '21 10:08 mlarabi

When you used nodemon directly was it the same version that npm-watch was using?

M-Zuber avatar Aug 08 '21 09:08 M-Zuber

No it's a more recent one. The latest probably as I always upgrade my packages when I can.

mlarabi avatar Aug 08 '21 11:08 mlarabi

Hi all, i hadthe same problem with my node red server. I want to restart it after every change. Thx to @mlarabi i could find a valid solution for me:

  • Installed kill-port and npm-watch as devDependencies
 "devDependencies": {
    "kill-port": "^1.6.1",
    "npm-watch": "^0.11.0"
  }
  • Added following config:
  "watch": {
      "watch.dev": "{nodes,dist}/*.js"
    },
  "scripts": {
    "watch.dev": "kill-port 1880 && node-red",
    "watch": "npm-watch"
  },

andreashauschild avatar Jan 28 '22 20:01 andreashauschild