Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mlarabi opened this issue Jul 12, 2021 · 5 comments
Open

Comments

@mlarabi
Copy link

mlarabi commented Jul 12, 2021

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

index.js.-.nodemon-restart-issue.-.Visual.Studio.Code.2021-07-12.05-01-24.mp4

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

index.js.-.nodemon-restart-issue.-.Visual.Studio.Code.2021-07-12.05-15-15.mp4
@abahrisd
Copy link

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

@mlarabi
Copy link
Author

mlarabi commented Aug 5, 2021

@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.

@M-Zuber
Copy link
Owner

M-Zuber commented Aug 8, 2021

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

@mlarabi
Copy link
Author

mlarabi commented Aug 8, 2021

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

@andreashauschild
Copy link

andreashauschild commented Jan 28, 2022

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"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants