I have a batch file that looks like this:
cd application1\backend\application1
start cmd /k "color 0F & npm run start"
cd ../../..
It consists of a series of these blocks, going in and out of several directories and starting node applications in each (and coloring the terminal it opens to run them).
What I've noticed is that when I shut down the terminal by killing it, or by killing the entire batch of them by right-clicking the icon in the system tray and selecting "Close all Windows", sometimes the ports they listen on remain in use. I get this error when I try to run them again:
Error: listen EADDRINUSE: address already in use ::1:3008
How can I ensure that when I shut down the terminals, the ports are released. I'm looking for something I can add to the batch file, like a flag I can add to starting the node application. Something like this:
start cmd /k /release-port-on-close "npm run start"
I'm also looking for a way that doesn't require manually shutting down each terminal one at a time, like hitting ctrl-c on each terminal.
Is there such a way?
I'm running Windows 10.