Updating Applications
The Electron team maintains , a free and open-source webservice that Electron apps can use to self-update. The service is designed for Electron apps that meet the following criteria:
- App runs on macOS or Windows
- App has a public GitHub repository
- Builds are code-signed
The easiest way to use this service is by installing , a Node.js module preconfigured for use with update.electronjs.org.
Install the module using your Node.js package manager of choice:
- npm
- Yarn
Then, invoke the updater from your app’s main process file:
main.js
By default, this module will check for updates at app startup, then every ten minutes. When an update is found, it will automatically be downloaded in the background. When the download completes, a dialog is displayed allowing the user to restart the app.
If you need to customize your configuration, you can pass options to update-electron-app or .
Using other update services
Depending on your needs, you can choose from one of these:
- Hazel – Update server for private or open-source apps which can be deployed for free on . It pulls from GitHub Releases and leverages the power of GitHub’s CDN.
- – Also uses GitHub Releases, but caches app updates on disk and supports private repositories.
- – Provides a dashboard for handling releases and does not require releases to originate on GitHub.
Once you’ve deployed your update server, you can instrument your app code to receive and apply the updates with Electron’s autoUpdater module.
First, import the required modules in your main process code. The following code might vary for different server software, but it works like described when using Hazel.
Check your execution environment!
Please ensure that the code below will only be executed in your packaged app, and not in development. You can use the API to check the environment.
main.js
const { app, autoUpdater, dialog } = require('electron')
Next, construct the URL of the update server feed and tell autoUpdater about it:
As the final step, check for updates. The example below will check every minute:
main.js
setInterval(() => {
autoUpdater.checkForUpdates()
Once your application is , it will receive an update for each new GitHub Release that you publish.
Now that you’ve configured the basic update mechanism for your application, you need to ensure that the user will get notified when there’s an update. This can be achieved using the autoUpdater API events:
main.js
Also make sure that errors are . Here’s an example for logging them to stderr
:
main.js
autoUpdater.on('error', (message) => {
console.error('There was a problem updating the application')
Because the requests made by autoUpdate aren’t under your direct control, you may find situations that are difficult to handle (such as if the update server is behind authentication). The url
field supports the file://
protocol, which means that with some effort, you can sidestep the server-communication aspect of the process by loading your update from a local directory. Here’s an example of how this could work.