npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

self-updater

v3.0.0

Published

Automatic GitHub/GitLab-based updater for PM2 or Docker services

Downloads

5

Readme

🚀 Self-Updater 2.0

Enterprise-grade GitOps automation for PM2, Docker, and custom service stacks. The self-updater monitors a Git repository, deploys new commits with zero-downtime safe guards, and restarts your runtime using hardened operational workflows.

✨ Highlights

  • 🔐 Production-ready configuration with schema validation, hooks, jitter control, and optional API tokens.
  • 📦 Repository lifecycle management – automatic cloning, fetch, reset, and dependency installation when package.json changes.
  • 🧭 Multi-platform restarts supporting PM2, Docker, Docker Compose, and arbitrary commands.
  • 🛰️ Robust watcher using GitHub/GitLab APIs with ETag caching and git fallback for air‑gapped environments.
  • 🧾 Structured logging with optional file output and persistent deployment state tracking.
  • 🛠️ Operational tooling: run-once, status, validate, PM2 ecosystem config, and container image.

📦 Installation

npm install -g self-updater

Note: The CLI reads environment variables from a local .env file (if present) before loading configuration.

⚙️ Configuration

Initialize an enterprise configuration interactively via CLI:

self-updater init \
  --repo https://github.com/your-org/your-service.git \
  --branch main \
  --path /srv/your-service \
  --type pm2 \
  --name your-service \
  --interval 120 \
  --jitter 30 \
  --auto-install \
  --pre "npm run migrate" \
  --post "npm run health-check" \
  --log-level info

This produces updater.config.json (overridable via SELF_UPDATER_CONFIG). Example:

{
  "version": 2,
  "repo": {
    "url": "https://github.com/your-org/your-service.git",
    "branch": "main",
    "remote": "origin",
    "authToken": "${GITHUB_TOKEN}"
  },
  "workspace": {
    "localPath": "/srv/your-service",
    "autoInstall": true,
    "installCommand": "npm ci"
  },
  "service": {
    "type": "pm2",
    "name": "your-service"
  },
  "schedule": {
    "intervalSeconds": 120,
    "jitterSeconds": 30
  },
  "hooks": {
    "preUpdate": "npm run migrate",
    "postUpdate": "npm run health-check"
  },
  "logging": {
    "level": "info",
    "file": "/var/log/self-updater/agent.log"
  }
}

Supported service targets

| Type | Behaviour | |----------|------------------------------------------------------------------------------------------------------| | pm2 | Runs pm2 reload <name> unless restartCommand is provided. | | docker | Runs docker restart <name> or docker compose [-f file] restart <service> when dockerCompose is enabled. | | command| Executes a fully custom restartCommand (required). |

Hooks & automation

  • preUpdate executes inside the workspace before the git reset.
  • postUpdate runs after service restart for smoke tests or cache warmups.
  • autoInstall triggers dependency installs when lock files change (package.json, package-lock.json, yarn.lock, pnpm-lock.yaml).

Logging & state

  • Log level: error, warn, info, or debug (default info).
  • Optional logging.file enables structured log files with automatic directory creation.
  • Deployment state persists in updater.state.json alongside the config for auditability.

🧰 CLI Commands

| Command | Description | |---------|-------------| | self-updater init | Create or update updater.config.json. | | self-updater start [--immediate] | Start the continuous watcher loop (suitable for PM2/systemd). | | self-updater run-once | Perform a single update cycle and exit (CI/CD or cron). | | self-updater status | Display local vs remote commit along with the last deployment timestamp. | | self-updater validate | Lint the configuration and exit non-zero on failure. |

🏃 Runtime options

Environment variables override defaults at runtime:

  • SELF_UPDATER_CONFIG – absolute path to the config file (default: <cwd>/updater.config.json).
  • SELF_UPDATER_LOG_LEVEL – force log level without rewriting the config.

A .env file placed next to the binary will be loaded prior to reading configuration, ideal for injecting tokens (e.g., GITHUB_TOKEN).

☸️ Container deployment

A hardened multi-stage Dockerfile is included. Build and run:

docker build -t self-updater .
docker run -d \
  --name self-updater \
  -v /srv/self-updater/config:/config \
  -v /srv/your-service:/srv/your-service \
  self-updater

Place your updater.config.json inside /srv/self-updater/config. The container entrypoint executes node bin/cli.js start --immediate.

♻️ PM2 integration

Use the supplied ecosystem.config.cjs template:

pm2 start ecosystem.config.cjs
pm2 save
pm2 status self-updater

Logs default to ./logs/out.log and ./logs/error.log; customize paths as needed.

🛡️ Operational guarantees

  • File-lock based concurrency guard prevents overlapping deployments.
  • Git operations use safe fetch + hard reset to ensure clean trees.
  • Automatic fallback to git ls-remote when API quota or connectivity issues occur.
  • Dependency install and hook execution are fully logged for traceability.

🧪 Development

npm install
npm run build
npm link
self-updater --help

📄 License

Apache 2.0 License © 2025 VectoDE

💬 Support

Open an issue or feature request at github.com/VectoDE/self-updater/issues