Getting Started: JS / Electron
Get started with our NPM package for JS & Electron.
If you are using pure nodejs and bundling your app using pkg or similar you can ignore Electron-specific steps.
-
Add Velopack to your
package.json
:npm install velopack
-
Add the following code to your entry point (eg.
index.js
) as early as possible (before any electron startup code etc.):const { VelopackApp } = require('velopack');
// Velopack builder needs to be the first thing to run in the main process.
// In some cases, it might quit/restart the process to perform tasks.
VelopackApp.build().run();
// ... your other app startup code here -
Add auto-updates somewhere to your app:
const { UpdateManager } = require('velopack');
async function updateApp()
{
const um = new UpdateManager();
um.setUrlOrPath("https://the.place/you-host/updates");
const updateInfo = await um.checkForUpdatesAsync();
if (!updateInfo) {
return; // no update available
}
await um.downloadUpdatesAsync(updateInfo.targetFullRelease, p => {
console.log(`progress: ${p}%`);
});
um.applyUpdatesAndRestart(updateInfo.targetFullRelease);
} -
If you are using electron/forge, you will need to add an asar unpack rule:
module.exports = {
packagerConfig: {
asar: {
// velopack contains native binaries which must remain unpacked
unpack: '**/node_modules/velopack/**',
},
},
} -
Compile your app to a binary (eg.
.exe
on Windows). Example using electron forge:npx electron-forge package
-
Install the
vpk
command line tool:dotnet tool update -g vpk
tipYou must have the .NET Core SDK 6 installed to use and update
vpk
-
Package your Velopack release / installers:
vpk pack -u MyAppUniqueId -v 1.0.0 -p /myBuildDir -e myexename.exe
✅ You're Done! Your app now has auto-updates and an installer.
You can upload your release to your website, or use the vpk upload
command to publish it to the destination of your choice.