Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Thanks to: @dathbe.

### Added

- Added configuration option for `User-Agent`, used by calendar & news module (#3255)
- [linter] Added prettier plugin for nunjuck templates (#3887)
- Add configuration option for `User-Agent`, used by calendar & news module (#3255)
- [linter] Add prettier plugin for nunjuck templates (#3887)
- [core] Add clear log for occupied port at startup (#3890)

### Changed

Expand Down
23 changes: 23 additions & 0 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ function Server (config) {
});

Log.log(`Starting server on port ${port} ... `);

// Add explicit error handling BEFORE calling listen so we can give user-friendly feedback
server.once("error", (err) => {
if (err && err.code === "EADDRINUSE") {
const bindAddr = config.address || "localhost";
const portInUseMessage = [
"",
"────────────────────────────────────────────────────────────────",
` PORT IN USE: ${bindAddr}:${port}`,
"",
" Another process (most likely another MagicMirror instance)",
" is already using this port.",
"",
" Stop the other process (free the port) or use a different port.",
"────────────────────────────────────────────────────────────────"
].join("\n");
Log.error(portInUseMessage);
return;
}

Log.error("Failed to start server:", err);
});

server.listen(port, config.address || "localhost");

if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
Expand Down