我试图在node.js应用程序中的端口3000和3080上启动一个进程。我想检查这些端口是否已经在运行进程,并想终止这些进程。
我尝试了portscanner并运行shell命令,但没有成功。
portscanner.findAPortInUse([3000], '0.0.0.0').then(port => { console.log(`Port ${port} is available!`); (async () => { await killPortProcess(3000); })(); });
Shell命令
exec("taskkill /PID 3000 /F", async function(err, stdout, stderr) { // React to callback console.log(stdout) });
我怎样才能做到这一点?