# Self-host CodePush API Service

CodePush is a service that enables React Native developers to deploy mobile app updates directly to their users’ devices. Microsoft is [retiring](https://learn.microsoft.com/en-us/appcenter/retirement) 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. <abbr>API </abbr> server ([https://github.com/microsoft/code-push-server/tree/main/api](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](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](https://github.com/microsoft/code-push-server)

# Server Setup

Prerequisites:

* NodeJS installed
    
* NPM installed
    
* Redis server installed and running
    

Download source code into `/opt`.

```bash
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.

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

At this point you can test run the <abbr>API</abbr> 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:

```ini
[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.

```bash
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.

```apache
# 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.

```bash
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](https://github.com/microsoft/code-push-server/tree/main/cli#getting-started)
