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

Previous process not being killed #161

Open
Guilherhast opened this issue Nov 7, 2023 · 0 comments
Open

Previous process not being killed #161

Guilherhast opened this issue Nov 7, 2023 · 0 comments

Comments

@Guilherhast
Copy link

When I try to run a node code the sub process is not being killed.

This is my npm script:

"scripts": {
    "watch": "npx watch --interval=1 'node src/index.js' src"
},

This is a minimal version of the app:

const express = require('express');

const PORT = 3000;
const HOST = 'localhost';

const app = express();

// Run
app.listen(PORT, HOST, ()=>{
	console.log(`Listening: ${HOST}:${PORT}`);
});

This is the error I get:

$ npm run watch

> iplogger@1.0.0 watch
> npx watch --interval=1 'node src/index.js' src

> Watching src
Listening: localhost:3000
# Affter save the file
node:events:492
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
    at Server.setupListenHandle [as _listen2] (node:net:1872:16)
    at listenInCluster (node:net:1920:12)
    at GetAddrInfoReqWrap.doListen [as callback] (node:net:2069:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:8)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1899:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 3000
}

Node.js v20.9.0

How can I tell the watch command to kill the previous process before starting a new?

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

1 participant