Example #1
0
 async.each([program.port, program.livereloadPort], function(port, cb) {
   processFinder.find(port, function(err, pids) {
     if (err) return cb(err);
     log.info("Killing process on port %s", port);
     pids.forEach(process.kill);
     cb();
   });
 }, callback);
Example #2
0
  server.start((e) => {
    if (e) {
      if (e.code === 'EADDRINUSE') {
        const finder = require('process-finder')
        finder.find({ elevate: false, port: program.port }, (startErr, pids) => {
          const msg =
`We were unable to start Gatsby on port ${program.port} as there's already a process
listening on that port (PID: ${pids[0]}). You can either use a different port
(e.g. gatsby serve-build --port ${parseInt(program.port, 10) + 1}) or stop the process
already listening on your desired port.`
          console.log(msg)
          process.exit()
        })
      } else {
        console.log(e)
      }
    } else {
      if (program.open) {
        opn(server.info.uri)
      }
      console.log('Listening at:', server.info.uri)
    }
  })