2.8 KiB
Updating Applications
There are several ways to update an Electron application. The easiest and officially supported one is taking advantage of the built-in Squirrel framework and Electron's autoUpdater module.
Deploying an update server
To get started, you first need to deploy a server that the autoUpdater module will download new updates from.
Depending on your needs, you can choose from one of these:
- Hazel – Pulls new releases from GitHub Releases and can be deployed for free on Now.
- Nuts – Also uses GitHub Releases, but caches app updates on disk and supports private repositories.
- electron-release-server – Provides a dashboard for handling releases
Implementing updates in your app
Once you've deployed your update server, continue with importing the required modules in your code. The following code might vary for different server software, but it works like described when using Hazel.
Important: Please ensure that the code below will only be executed in your packaged app. You can use electron-is-dev to check for the environment.
const { app, autoUpdater } = require('electron')
Next, construct the URL of the update server and tell autoUpdater about it:
const server = 'https://your-deployment-url.com'
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)
As the final step, check for updates (the example below will check every minute):
setInterval(() => {
autoUpdater.checkForUpdates()
}, 60000)
That's all. Once built, your application will receive an update for each new GitHub Release that you create.
Further steps
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 events:
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
// Show a notification banner to the user that allows triggering the update
})
Also make sure that errors are
being handled. Here's an example
for logging them to stderr
:
autoUpdater.on('error', message => {
console.error('There was a problem updating the application')
console.error(message)
})