article illustration npm Scripts for Capacitor OTA Updates Explained
Development, Mobile, Updates
Last update: April 13, 2025

npm Scripts for Capacitor OTA Updates Explained

Learn how to automate OTA updates for your Capacitor app using npm scripts, enhancing deployment efficiency and user experience.

Updating your Capacitor app has never been easier. By combining Over-The-Air (OTA) updates with npm scripts, you can automate deployments, save time, and ensure your users always have the latest version - without waiting for app store approvals.

Here’s what you’ll learn:

  • How to set up npm scripts for OTA updates.
  • Integrating updates into CI/CD pipelines for automation.
  • Managing app versions, security, and testing updates.
  • Why Capgo is a reliable platform for managing OTA updates.

Key Benefits:

  • Automate updates with one command.
  • Deploy updates securely with encryption.
  • Integrate updates into workflows like GitHub Actions.
  • Save time with tools like Capgo, which delivers updates in under 500ms.

Quick Setup Example:

  1. Install tools: npm install @capgo/cli --save-dev
  2. Configure updates in capacitor.config.json.
  3. Add npm scripts like deploy:production to streamline deployment.

With platforms like Capgo offering fast updates (95% user adoption in 24 hours) and affordable pricing, managing OTA updates has never been more efficient.

Explore Capawesome’s New Ionic Capacitor Live Update …

Capawesome

npm Scripts Setup for OTA Updates

Here’s how to configure npm scripts to manage Capacitor OTA updates effectively. This involves installing necessary packages, setting up configurations, and creating deployment scripts.

Installing Required Packages

First, install the required packages. The Capgo CLI tool simplifies this process with built-in commands:

Terminal window
npm install @capgo/cli --save-dev
npm install @capacitor/cli --save-dev

Then, initialize the OTA configuration using the following command:

Terminal window
npx @capgo/cli init

Configuring OTA Updates

Update your capacitor.config.json file with the following settings to prepare your app for OTA updates:

{
"appId": "com.your.app",
"appName": "Your App",
"plugins": {
"CapacitorUpdates": {
"autoUpdate": true,
"updateUrl": "https://api.capgo.app/updates",
"statsUrl": "https://api.capgo.app/stats"
}
}
}

This configuration ensures your app can fetch updates automatically and report statistics.

Creating Deployment Scripts

Add these npm scripts to your package.json file to streamline the build and deployment process:

{
"scripts": {
"build:web": "npm run build",
"build:update": "npx @capgo/cli build",
"deploy:update": "npx @capgo/cli upload",
"deploy:production": "npm run build:web && npm run build:update && npm run deploy:update"
}
}
  • build:web: Builds web assets, typically used during development and deployment.
  • build:update: Prepares the update package for OTA updates.
  • deploy:update: Uploads the update package to Capgo.
  • deploy:production: Handles the complete build and deployment workflow, ideal for production releases.

“We configure your CI/CD pipeline directly in your preferred platform, whether it’s GitHub Actions, GitLab CI, or others. We don’t host CI/CD or charge you to maintain it.” - Capgo [1]

Setting Environment Variables

To finalize the setup, define these environment variables:

Terminal window
CAPGO_TOKEN=your_api_token
CAPGO_APP_ID=your_app_id

Compatibility and Reliability

The Capgo CLI supports Capacitor 6 and 7, ensuring it works with the latest versions while maintaining dependable update functionality.

Script CommandPurposeWhen to Use
build:webBuilds web assetsDuring development and deployment
build:updatePrepares the update packageBefore each OTA update
deploy:updateUploads updates to CapgoWhen updates are ready to push
deploy:productionHandles the full workflowFor production releases

Adding npm Scripts to CI/CD

Integrating npm scripts into your CI/CD pipeline can simplify the Over-The-Air (OTA) update process for Capacitor apps. Here’s a guide to setting up automated deployments efficiently.

CI/CD Build Setup

Configure your CI/CD environment with the necessary variables and steps:

environment:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
CAPGO_APP_ID: ${{ secrets.CAPGO_APP_ID }}
NODE_ENV: production

For optimal performance, include caching in your build process:

cache:
paths:
- node_modules/
- .npm/
- dist/

GitHub Actions Setup Guide

GitHub Actions

To automate your deployment workflow, create a .github/workflows/ota-deploy.yml file with this configuration:

name: Deploy OTA Update
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run deployment
run: npm run deploy:production
env:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
CAPGO_APP_ID: ${{ secrets.CAPGO_APP_ID }}

This setup ensures your app is deployed automatically whenever changes are pushed to the main branch.

Update Recovery and Fixes

To handle potential update failures, include recovery mechanisms in your CI/CD pipeline. These features can help maintain app stability:

Recovery FeatureImplementationPurpose
Version Rollbacknpm run revert:updateReverts to the last stable version
Health Checksnpm run verify:updateEnsures the update is functioning properly
Auto-retrymaxRetries: 3 in configAttempts the update multiple times

You can enhance your deployment script to manage errors automatically. For example:

Terminal window
npm run deploy:production || npm run revert:update

This script ensures that if a deployment fails, the system will revert to the previous stable version. Additionally, your CI/CD pipeline can send status reports and trigger notifications through your preferred platform.

OTA Update Management Tips

Effectively managing OTA updates involves keeping a close eye on version control, rigorous testing, and strong security protocols. Here’s how you can streamline updates using npm scripts.

Version Management

Semantic versioning is a simple way to manage app updates. Here’s an example configuration:

{
"version": "2.5.0",
"scripts": {
"update:major": "npm version major && npm run deploy:update",
"update:minor": "npm version minor && npm run deploy:update",
"update:patch": "npm version patch && npm run deploy:update"
}
}

Using separate channels like Production, Beta, Alpha, and Hotfix allows for targeted rollouts. These strategies make it easier to test updates and ensure smooth deployments.

Update Testing Steps

Automated testing is essential for catching issues early. Use npm scripts to simplify the process:

Terminal window
npm run test:update -- --channel=beta
npm run verify:deployment
npm run monitor:metrics

Testing updates in stages through different channels helps identify problems before they reach all users. Automated rollback procedures are another safety net to maintain app stability.

Update Security Measures

Security is critical in OTA updates. Here are some key measures to put in place:

Security FeatureImplementationPurpose
End-to-End EncryptionProvided by CapgoProtects against data breaches
Update SigningPackage verificationConfirms updates are genuine
Access ControlRole-based permissionsRestricts team access

“The only solution with true end-to-end encryption, others just sign updates” - Capgo [1]

To ensure updates are secure, configure npm scripts to validate everything before deployment:

{
"scripts": {
"predeploy": "npm run security:check",
"deploy": "capgo upload --encrypt",
"security:check": "npm audit && npm run validate:bundle"
}
}

Additionally, enforce channel-specific security policies and use role-based permissions to control who can distribute updates. This adds an extra layer of protection to your deployment process.

OTA Update Platform Options

Choosing the right OTA update platform is crucial for effectively integrating npm scripts into your workflow. Prioritize factors like performance, security, and compatibility with your existing tools. Here’s a breakdown of Capgo and other market options to help you make an informed decision.

Capgo Features

Capgo

Capgo is designed specifically for Capacitor OTA updates, offering an average update speed of 434 milliseconds and achieving a 95% user update rate [1]. It provides seamless integration with npm scripts, as shown in the example below:

{
"scripts": {
"deploy:production": "capgo upload --channel production",
"deploy:beta": "capgo upload --channel beta --encrypt",
"rollback": "capgo revert --channel production"
}
}

Capgo ensures secure updates with end-to-end encryption and allows for strategic deployments through its channel system. With 23.5 million updates delivered across 750 production apps, it has proven its scalability and reliability [1].

Platform Comparison

When using npm scripts, it’s essential to evaluate platforms based on encryption, speed, and CI/CD integrations. Here’s a quick comparison of features:

FeatureImplementation DetailsUpdate Success Rate
End-to-End EncryptionFull encryption support82% worldwide [1]
Update Speed114 ms for a 5 MB bundleGlobal CDN delivery
CI/CD IntegrationGitHub Actions, GitLab CICustom workflows

“We practice agile development and @Capgo is mission-critical in delivering continuously to our users!”
– Rodrigo Mantica [1]

The OTA update market has shifted significantly, especially after Microsoft Code Push shut down in 2024, with Appflow set to follow in 2026. Simon Flack shared his perspective on these changes:

“We are currently giving a try to @Capgo since Appcenter stopped live updates support on hybrid apps and @AppFlow is way too expensive.” [1]

Cost is another important consideration for teams. Capgo offers CI/CD capabilities at approximately $300 per month, a much lower cost compared to the $6,000 annual fees of enterprise-level alternatives [1].

When implementing npm scripts in your deployment workflow, consider these factors:

  • API responsiveness for smooth script execution
  • Channel management for targeted updates
  • CI/CD pipeline integration for streamlined processes
  • Strong security measures to ensure compliance
  • Affordability for scaling without breaking the budget

Capgo’s ability to handle complex npm script configurations while maintaining high performance makes it a strong contender for OTA update management.

Conclusion

Main Points Review

Using npm scripts simplifies the process of managing Capacitor OTA updates. When integrated into CI/CD pipelines, these scripts help automate deployments while ensuring security and maintaining performance levels.

Here are the key areas of focus:

  • Automated Deployment: Handles versioning and deployment without manual intervention.
  • Security Measures: Ensures updates are distributed securely with end-to-end encryption.
  • Performance Monitoring: Keeps track of update delivery speeds and success rates.

These features highlight why Capgo stands out as a reliable tool for managing OTA updates.

Capgo Benefits

With Microsoft CodePush shutting down in 2024, the OTA update landscape has shifted. Capgo has emerged as a dependable solution, having successfully delivered 23.5 million updates across 750 production apps [1].

“We practice agile development and @Capgo is mission-critical in delivering continuously to our users!” – Rodrigo Mantica [1]

Capgo’s performance metrics speak for themselves:

Performance IndicatorAchievement
Average API Response434 ms worldwide
Bundle Download Speed114 ms for 5 MB
Update Success Rate82% globally

At $300 per month for CI/CD integration - compared to $6,000 annually for enterprise-level solutions - Capgo offers a secure, reliable, and cost-efficient option for managing OTA updates [1].

Authored By

Instant Updates for CapacitorJS Apps

Push updates, fixes, and features instantly to your CapacitorJS apps without app store delays. Experience seamless integration, end-to-end encryption, and real-time updates with Capgo.

Get Started Now

Latest from news

Capgo gives you the best insights you need to create a truly professional mobile app.

blog illustration 5 Common OTA Update Mistakes to Avoid
Development, Security, Updates
April 13, 2025

5 Common OTA Update Mistakes to Avoid

Read more
blog illustration 5 Security Best Practices for Mobile App Live Updates
Development, Mobile, Updates
January 14, 2025

5 Security Best Practices for Mobile App Live Updates

Read more