Skip to main content
Background modules run in the Electron main process (Node.js). They’re optional — only add one when you need persistent server-side logic that outlives UI navigation: registering Express routes, maintaining a connection, or running scheduled tasks.

When to Use a Background Module

Use a background module when you need to:
  • Expose an HTTP API to your UI module (via Express routes)
  • Handle IPC messages from the renderer
  • Maintain a persistent connection (WebSocket, database, etc.)
  • Run background polling or scheduled work
  • Access Node.js APIs not available in the renderer
If your plugin only displays data and reacts to user interaction, a UI module alone is sufficient.

Declaring a Background Module

Add the background entry to your Vite config:
Adding a background module only adds the background entry — keep react() in the plugins array. createPluginConfig does not inject it for you, and the dev server’s Fast Refresh preamble fails without it. See Getting Started for details. The shell discovers background modules automatically by checking for the compiled background/index.js in your plugin’s install directory — no plugin.json configuration is needed.

The PluginBackgroundModule Contract

Your background entry module must export onStart and onStop. Use the createPlugin helper for type safety and validation:
The createPlugin helper validates your module at import time and gives you full type inference on ctx — no manual type imports needed. The shell requires this default export pattern; named exports are not supported.

The Plugin Context

Both onStart() and onStop() receive a ctx object that gives scoped access to shell infrastructure, live flight state, and the pilot. Each accessor is documented on its own page under Plugin Context: To talk to your UI module from the background, see Background ↔ UI Communication.

Lifecycle Summary

  1. Shell starts and initialises auth
  2. Shell calls onStart(ctx) for each plugin with a background module
  3. If onStart() throws, the plugin is marked errored — other plugins still load
  4. On shutdown, shell calls onStop(ctx) for each running background module
  5. After an OTA update, the shell calls onStop(ctx) then onStart(ctx) fresh