Skip to content

Commit

Permalink
add pretty message if port already use(vercel#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
dex157 committed Jan 30, 2017
1 parent 0d2af80 commit 0efd6f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bin/next-dev
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ srv.start(argv.port)
}
})
.catch((err) => {
console.error(err)
if (err.code === 'EADDRINUSE') {
console.error(`Port ${argv.port} is already in use.\nUse \`npm run dev -- -p <some other port>\`.`)
} else {
console.error(err)
}
process.exit(1)
})
7 changes: 5 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ export default class Server {
await this.prepare()
this.http = http.createServer(this.getRequestHandler())
await new Promise((resolve, reject) => {
this.http.listen(port, (err) => {
if (err) return reject(err)
this.http.on('error', (error) => {
reject(error)
})
this.http.on('listening', () => {
resolve()
})
this.http.listen(port, () => {})
})
}

Expand Down

0 comments on commit 0efd6f9

Please sign in to comment.