1

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

> graphql-basics@1.0.0 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?
Phill Alexakis
  • 1,325
  • 5
  • 20

2 Answers2

2

You have 2 option to resolve this issue.

  1. Execute killall node command using root user
  2. Set the available port. var port = process.env.PORT || 8080;
Jenish
  • 184
  • 1
  • 11
1

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"
  }
}
myeongkil kim
  • 2,020
  • 4
  • 12
  • 19