Skip to content

Commit 2175153

Browse files
nol166code-asher
authored andcommitted
Add port in use message (#418)
* Add clear error message if port is in use * Add bold function for text/numbers * remove unused dependency: * remove unused line break * Change logger message * Use NodeJS.ErrnoException type * Add back check for error code
1 parent dcf409a commit 2175153

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/server/src/cli.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Error.stackTraceLimit = Infinity;
3838
if (isCli) {
3939
require("nbin").shimNativeFs(buildDir);
4040
}
41+
// Makes strings or numbers bold in stdout
42+
const bold = (text: string | number): string | number => {
43+
return `\u001B[1m${text}\u001B[0m`;
44+
};
4145

4246
(async (): Promise<void> => {
4347
const args = commander.args;
@@ -234,7 +238,12 @@ if (isCli) {
234238
logger.info(`WebSocket closed \u001B[0m${req.url}`, field("client", id), field("code", code));
235239
});
236240
});
237-
241+
app.wss.on("error", (err: NodeJS.ErrnoException) => {
242+
if (err.code === "EADDRINUSE") {
243+
logger.error(`Port ${bold(options.port)} is in use. Please free up port ${options.port} or specify a different port with the -p flag`);
244+
process.exit(1);
245+
}
246+
});
238247
if (!options.certKey && !options.cert) {
239248
logger.warn("No certificate specified. \u001B[1mThis could be insecure.");
240249
// TODO: fill in appropriate doc url

0 commit comments

Comments
 (0)