What it does
The server loader (@nanoforge-dev/loader-server) runs the server app of your game.
nf start starts one for each server app, pointed at the app’s build
folder (-d, --dir <dir>, required).
It lists the files of the build folder, finds main.js at its root, and starts a child process
(the worker) that loads main.js and calls its main function. When the worker exits (a crash,
or a process.exit() in your game), the server loader stops too, even with --watch.
What your server’s main receives
The
main.ts that nf new generates passes this object to app.init.
files is built once, when the loader starts. A file added to the build later is not in it until
the loader restarts (stop and start nf dev or nf start).
Restart on change
With--watch (set by nf dev), the loader watches the build folder.
When a file changes, it stops the worker and starts a new one, with a clean state. Changes closer
than 100 ms count as one restart.
Players connected to the old worker lose their connection when it restarts.
Common errors
No game dir specified: the loader was started without-d.nf startalways passes it; check the server’sout.dir.No main.js found: the build folder has nomain.jsat its root. Runnf build, and keep the server entry file namedmain.ts.- An error thrown by your game: the worker prints it and exits, and the server loader stops
with it. Fix the error, then restart
nf dev(ornf start).