Skip to main content
Module

x/esm/HOSTING.md

A fast, global CDN for NPM packages with ESM format.
Go to Latest
File

Self-Hosting

esm.sh provides a fast, global content delivery network publicly which powered by Cloudflare. You may also want to host esm.sh by yourself.

To serve esm.sh, You will need Go 1.18+ to run and compile the server. The server runtime will install the nodejs (16 LTS) automatically.

Clone code

git clone https://github.com/ije/esm.sh
cd esm.sh

Configration

To configure the server, you need to create a config.json file then pass it to the server bootstrap command. For example:

// config.json
{
  "port": 8080,
  "tlsPort": 443,
  "workDir": "/var/www/esmd",
  "storage": "local:/var/www/esmd/storage",
  "origin": "https://esm.sh",
  "npmRegistry": "https://npmjs.org/registry",
  "npmToken": "xxxxxx"
}

You can find all the server options in config.exmaple.jsonc. (Note: the config.example.jsonc is not a valid JSON file, it’s a JSONC file.)

Run the sever locally

go run main.go --config=config.json --dev

Then you can import React from http://localhost:8080/react

Deploy to remote host with the quick deploy script

Please ensure the supervisor has been installed on your host machine.

./scripts/deploy.sh --init

Deploy with Docker

An example Dockerfile is found in the root of this project.