端口“已在使用中"每台服务器重新启动后 [英] Port "already in use" after each server restart

查看:159
本文介绍了端口“已在使用中"每台服务器重新启动后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在寻求有关特殊问题的帮助.每次我停止并重新启动服务器时,都会收到以下消息:

Searching for help with peculiar issue. Each time I stop and restart the server, I get this message:

Jim@Jim-PC MINGW64 ~/nodeProjects/express-locallibrary-tutorial
$ npm start

> express-locallibrary-tutorial@0.0.0 start C:\Users\Jim\nodeProjects\express-locallibrary-tutorial
> node ./bin/www

Port 3300 is already in use
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! express-locallibrary-tutorial@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express-locallibrary-tutorial@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Jim\AppData\Roaming\npm-cache\_logs\2017-09-19T17_39_10_578Z-debug.log

我将端口更改为3301,它可以工作.我停止并重新启动服务器,并收到错误3301已经在使用中.我将端口更改为3302,它可以工作.停止并启动,然后得到错误消息:3302已经被使用.

I change the port to 3301, it works. I stop and restart the server and receive an error that 3301 is already in use. I change the port to 3302 and it works. Stop and start and get error that 3302 is already in use.

几天前,我停止在另一个应用程序上针对同一问题使用nodemon,然后停止运行.对于此应用程序,我安装了nodemon,但没有全局安装,但遇到了问题并卸载了它.但是问题仍然存在.

I stopped using nodemon several days ago for the same issue on another application, and it stopped. For this application, I installed nodemon, but not globally, ran into issues and uninstalled it. But the issue persists.

如果有人遇到此问题,我将不胜感激.

I would appreciate any ideas on a solution if anyone has encountered this.

推荐答案

我们到了2020年,这个问题似乎尚未完全解决.

Here we are in 2020 and this issue seems to not have been fully solved.

我在这里为nodemon 编写此解决方法,因为目前这是Google在Google上查询nodemon The port or ip 0.0.0.0 is already in use的第一个结果.

I'm writing this workaround for nodemon here, because at the present time this is the first result on google for the query nodemon The port or ip 0.0.0.0 is already in use.

  1. kill-port节点软件包安装为dev依赖项:npm install kill-port --save-dev
  2. 在项目的根目录中创建一个nodemon.json文件,其中包含(用端口替换18000,例如3000):

  1. Install the kill-port node package as a dev dependency: npm install kill-port --save-dev
  2. Create a nodemon.json file in the root of your project, containing (replace 18000 with your port, eg 3000):

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

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

然后,在您的package.json文件中,具有以下内容:

Then, in your package.json file, have something like this:

"scripts": { "start-dev": "nodemon app.js", },

"scripts": { "start-dev": "nodemon app.js", },

然后使用npm run start-dev

这篇关于端口“已在使用中"每台服务器重新启动后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆