Skip to content

Commit 7da7c43

Browse files
committed
parse-community#510 Detect when the port you are trying to run the server on is already in use.
1 parent 831c2ee commit 7da7c43

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
@@ -188,6 +188,17 @@ function ParseServer({
188188

189189
api.use(middlewares.handleParseErrors);
190190

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

0 commit comments

Comments
 (0)