Skip to content

Commit 017863f

Browse files
committed
Merge pull request #582 from IlyaDiallo/510
#510 Detect when the port you try to run the server on is already in use
2 parents 8ce8e2b + 2482475 commit 017863f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ function ParseServer({
187187

188188
api.use(middlewares.handleParseErrors);
189189

190+
191+
process.on('uncaughtException', (err) => {
192+
if( err.code === "EADDRINUSE" ) { // user-friendly message for this common error
193+
console.log(`Unable to listen on port ${err.port}. The port is already in use.`);
194+
process.exit(0);
195+
}
196+
else {
197+
throw err;
198+
}
199+
});
200+
190201
return api;
191202
}
192203

0 commit comments

Comments
 (0)