我在这篇文章中寻找答案:Node / Express: EADDRINUSE, Address already in use - Kill server
虽然我不认为它回答了我的问题,因为我不想终止正在运行的进程而是重新启动服务。
$ npm run start
> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="593e2b3829312835743b382a303a2a196877697769" rel="noreferrer noopener nofollow">[email protected]</a> start /home/phill/Documents/graphql-course/graphql-basics
> nodemon src/index.js --exec babel-node
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node src/index.js`
The server is up!
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/index.js`
events.js:174
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::4000
基本上它会重新启动服务器而不杀死先前的进程?
Manually killing the process won't fix this issue
这是我的package.json
{
"name": "graphql-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/index.js --exec babel-node",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"graphql-yoga": "^1.14.10"
},
"devDependencies": {
"nodemon": "^1.17.5"
}
}
const server = new GraphQLServer({
typeDefs,
resolvers
})
server.start(() => {
console.log('The server is up!')
})
//should i use process.on('SIGTERM',...) and kill it somehow?
最佳答案
您有 2 个选项来解决此问题。
- 使用root用户执行
killall node
命令 - 设置可用端口。
var port = process.env.PORT || 8080;
关于node.js - 错误:监听 EADDRINUSE:地址已在使用中:::4000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65506937/