node.js - Npm script that finds and kills port that's in use -


i'm on windows machine , every time quit node process, , try restart again error: listen eaddrinuse :::8004

i have

netstat -o -n -a | findstr 0.0:8004 taskkill /f /pid <pid> 

how can write script finds , kills pid doing npm kill?

1) problem isn't killing server, it's closing port upon exiting. program missing server.close() in process.on('exit', ..) , process.on('uncaughtexception', ..).

2) first argument allowed next npm 1 of predefined set. read output of npm that.

3) answer question, , lazy work, can put 2 commands inside batch file, set listening port parameter , declare script section in package.json,

{   "name": "myserver",   "scripts": {     "kill": "killserver.bat"   }, } 

then use npm run kill -- 8004, port number being of course parameter in batch. note longer , more complicated calling batch directly. see https://docs.npmjs.com/cli/run-script, it's useful understand possibilities offered npm.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -