Reputation: 1499
I've been on this post for the answer: Node / Express: EADDRINUSE, Address already in use - Kill server
Although I don't think that it answers my question, as I wouldn't like to kill the running process but to restart the service.
$ npm run start
> [email protected] 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
Basically it restarts the server without killing the previous process?
Manually killing the process won't fix this issue
this is my 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?
Upvotes: 2
Views: 5533
Reputation: 1
you have to kill the existing running server in the port 4000.
npx kill-port 4000
Upvotes: 0
Reputation: 2576
Nodemon offers a delay option. I solved it by inserting that option in the same situation as you. Please refer to the link below. github.com/nodemon/delaying-restarting
"start": "nodemon --delay 300ms src/index.js --exec babel-node"
{
"name": "graphql-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon --delay 300ms 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"
}
}
Upvotes: 2
Reputation: 234
You have 2 option to resolve this issue.
killall node
command using root uservar port = process.env.PORT || 8080;
Upvotes: 2