Skip to main content

Command Palette

Search for a command to run...

Self-host CodePush API Service

Updated
2 min read
Self-host CodePush API Service
H

I am a developer from Malaysia. I work with PHP most of the time, recently I fell in love with Go. When I am not working, I will be ballroom dancing :-)

CodePush is a service that enables React Native developers to deploy mobile app updates directly to their users’ devices. Microsoft is retiring this service on 31 March 2025. Fortunately Microsoft open sourced the CodePush server on GitHub, allowing anyone to self-host CodePush server.

CodePush API service consist of 2 components:

  1. API server (https://github.com/microsoft/code-push-server/tree/main/api)

  2. CLI tool for managing CodePush Server (https://github.com/microsoft/code-push-server/tree/main/cli)

This article provides instructions on how to install these 2 components. The setup was performed on CentOS, but it can be easily adapted to other Linux Distro.

CodePush GitHub: https://github.com/microsoft/code-push-server

Server Setup

Prerequisites:

  • NodeJS installed

  • NPM installed

  • Redis server installed and running

Download source code into /opt.

cd /opt
sudo git clone https://github.com/microsoft/code-push-server.git

Copy /opt/code-push-server/api/.env.example to /opt/code-push-server/api/.env and modify it:

  • Set EMULATED to true, unless you want to setup Azure Blob Storage for storage.

  • Configure Redis REDIS_HOST, REDIS_PORT, REDIS_KEY.

Build the app.

cd /opt/code-push-server/api
sudo npm install
sudo npm run build

At this point you can test run the API server: npm run start:env. By default the server binds to 127.0.0.1:3000, accepting HTTP requests.

Automatically Start The Server

Create /etc/systemd/system/code-push-server.service file with the following content:

[Unit]
Description="CodePush Server"
Documentation="https://github.com/microsoft/code-push-server/blob/main/api/README.md"
After=network.target

[Service]
WorkingDirectory=/opt/code-push-server/api
ExecStart=/usr/bin/npm run start:env
Restart=always
Environment=NODE_ENV=production
# Limit the number of restarts in a short period to prevent excessive resource usage
RestartSec=10 # Wait 10 seconds before restarting
LimitNOFILE=65536 # Increase file descriptor limit (important for production)

[Install]
WantedBy=multi-user.target

Enable and start the service.

sudo systemctl enable --now code-push-server

Setup Apache Reverse Proxy

If you are using a different web server, consult the relevant documentation for instructions on reverse proxy setup. By default CodePush server is not accessible from public. This VirtualHost configuration will make it publicly accessible.

# Desc: Self-hosted CodePush server.
# Ref: https://github.com/microsoft/code-push-server/blob/main/api/README.md
<VirtualHost *:80>
        ServerName example.com

        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/

        CustomLog logs/example.com-access.log combined
        ErrorLog logs/example.com-error.log
</VirtualHost>

CLI Setup

Prerequisites:

  • NodeJS installed

  • NPM installed

  • Already checkout code to /opt/code-push-server

Build the app.

cd /opt/code-push-server/cli
sudo npm install
sudo npm run build
sudo npm install -g

It will install an executable at /usr/local/bin/code-push-standalone. Follow the rest of the instruction to configure CodePush server: https://github.com/microsoft/code-push-server/tree/main/cli#getting-started

More from this blog

Hong's Tech Blog

110 posts

The blog is older than you know. I prefer counting from the emergence of one integral anomaly to the emergence of the next, in which case this is the forth version.