Skip to content

Commit 1adfb8e

Browse files
Add documentation for server:watch script (#336)
The new script was introduced in MagicMirrorOrg/MagicMirror#3920.
1 parent 6889efc commit 1adfb8e

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

configuration/introduction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following properties can be configured, place them above the modules item:
5959
| `electronOptions` | An optional array of Electron (browser) options. This allows configuration of e.g. the browser screen size and position (example: `electronOptions: { fullscreen: false, width: 800, height: 600 }`). Kiosk mode can be enabled by setting `kiosk: true`, `autoHideMenuBar: false` and `fullscreen: false`. More options can be found [here](https://github.com/electron/electron/blob/master/docs/api/browser-window.md). This will most likely be used in advanced installations, below. | [] |
6060
| `electronSwitches` | An optional array of Electron switches. This allows configuration of electron app itself. <br> This properties will not affect the `serveronly` mode. Usually normal `MM` users don't need this property, but if you are a hard-core hacker, you might need this to handle Electron itself over `MagicMirror` provides. More options can be found [here](https://www.electronjs.org/docs/latest/api/command-line-switches) (Not all available switches are described there.)<br>example:`electronSwitches:["enable-transparent-visuals", "disable-gpu"];` | [] |
6161
| `customCss` | The path of the `custom.css` stylesheet. The default is `css/custom.css`. | `css/custom.css` |
62+
| `watchTargets` | An optional array of file paths to monitor when using `node --run server:watch`. When any of these files change, the server automatically restarts and connected browsers reload. Particularly useful when frequently modifying `config.js`, `custom.css`, or module files during development or setup. Example: `watchTargets: ["config/config.js", "css/custom.css", "modules/MMM-MyModule/MMM-MyModule.js"]`. See [Development Mode](/core-development/debugging.html#development-mode-with-auto-reload) for more details. | `undefined` |
6263

6364
After the above options, you will then add modules. See
6465
[module configuration](/modules/configuration.md) for more information.

core-development/debugging.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,50 @@ Developer consoles in browsers and the Electron app (typically CTRL+SHIFT+I to
3030
toggle open/close) can be used to set client-side breakpoints, step through
3131
scripts and inspect variables.
3232

33+
## Watch Mode with Auto-Reload
34+
35+
For active development, MagicMirror² provides a `server:watch` script that automatically restarts the server and reloads connected browsers when files change:
36+
37+
```sh
38+
node --run server:watch
39+
```
40+
41+
This mode monitors files specified in your `config.js` under the `watchTargets` property:
42+
43+
```js
44+
let config = {
45+
watchTargets: [
46+
"config/config.js",
47+
"css/custom.css",
48+
"modules/MMM-MyModule/MMM-MyModule.js",
49+
"modules/MMM-MyModule/node_helper.js"
50+
],
51+
// ... rest of config
52+
};
53+
```
54+
55+
When any monitored file changes:
56+
1. The server automatically restarts
57+
2. Waits for the port to become available
58+
3. Sends a reload notification to all connected browsers via Socket.io
59+
4. Browsers automatically refresh to show the changes
60+
61+
This creates a seamless development experience where you can edit code, save, and see the results within seconds without manual restarts.
62+
63+
**Note:** If `watchTargets` is empty or undefined, the watcher starts but monitors nothing.
64+
3365
## Logging
3466

3567
While there are no log files produced by the server, info is reported in two
3668
different places:
3769

38-
- The console when running from `npm run start` or `npm run server`.
70+
- The console when running from `node --run start`, `node --run server`, or `node --run server:watch`.
3971
- This is separated into two streams, `console.log()` is output as the
4072
`stdout` stream, and
4173
- `console.error()` is output as the `stderr` stream.
4274
- These can be redirected to files when starting the server. `>` will redirect
4375
`stdout`, and `2>` will redirect `stderr`. `2>&1` will combine both streams:
44-
`npm run start > out.log 2>&1`
76+
`node --run start > out.log 2>&1`
4577
- The browser's developer console (typically CTRL+SHIFT+I to toggle open/close)
4678
will have output from scripts that run on the browser.
4779

@@ -113,5 +145,5 @@ script, such as `start:dev`:
113145
Or when running from the command line (Linux example):
114146

115147
```sh
116-
TZ=Europe/Madrid npm run start:dev
148+
TZ=Europe/Madrid node --run start:dev
117149
```

0 commit comments

Comments
 (0)