nodemon: Nodemon - app crashes when restarting due to Node already running on that port

  • nodemon -v:1.18.6
  • node -v:8.10.0
  • Operating system/terminal environment:
  • Command you ran:

Expected behaviour

Nodemon closes the old Node process and creates a new one

Actual behaviour

Nodemon doesn’t stop the old Node process and then the new one crashes because it’s trying to run on the same port

Steps to reproduce

Run Nodemon and save the file after making changes


If applicable, please append the --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 11
  • Comments: 20 (5 by maintainers)

Commits related to this issue

Most upvoted comments

My solution:

yarn add kill-port

in nodemon.json:

{
  "events": {
    "restart": "kill-port 5000",
    "crash": "kill-port 5000"
  },
  "delay": "1500"
}

Replace your port:

"restart": "kill-port [my port]",

Change the port to any other port number, just not 3000. for exemple make it 5000 or 4000 it will be okay

with port = 4000 image


With port = 3000 image

Just want to follow up. If the ONLY thing I change in my shrinkwrap is the pstree version, which is then used in a docker container and npm runs npm ci, then with version 1.1.2 it will always fail to reload, with 1.1.0 it will always reload successfully.

Looks like 1.1.1 and 1.1.2 were added in quick succession 4 days ago. If I force it to use 1.1.1 nodemon throws this error:

/opt/.../node_modules/nodemon/lib/monitor/run.js:336
        spawn('kill', ['-s', sig, child.pid].concat(kids.map(p => p.PID)))
                                                         ^
TypeError: Cannot read property 'map' of undefined
    at /opt/.../node_modules/nodemon/lib/monitor/run.js:336:58
    at /opt/.../node_modules/pstree.remy/lib/tree.js:53:11
    at ChildProcess.onClose (/opt/.../node_modules/pstree.remy/lib/tree.js:80:9)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:557:12)

@remy

@arabrain When I tried restarting on different ports I still had the same issue. Right now my fix is to use the following command in the command line: lsof -ti tcp:5000 | xargs kill and then running npm run dev but even then sometimes I’ll get the same error.

@Aymather u need to kill the process work on the port for exemple 3000 and restart everything.Or u will take my idea, that mean u will change the port every time when u have the same problem.