Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 7, 2026·3 min de lecture

forever — Keep Node.js Scripts Running Continuously

A CLI tool that ensures a given Node.js script runs continuously, restarting it on failure.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
forever Overview
Commande d'installation directe
npx -y tokrepo@latest install 118e56f4-799e-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

forever is a Node.js CLI tool and library that keeps your scripts running continuously. If a process crashes or exits unexpectedly, forever automatically restarts it, making it a straightforward solution for keeping Node.js services alive in production or development environments without complex orchestration.

What forever Does

  • Starts Node.js scripts as background daemon processes
  • Automatically restarts scripts when they crash or exit
  • Provides listing, stopping, and log management for running processes
  • Supports custom environment variables and command-line arguments per process
  • Can run as both a CLI tool and a programmatic Node.js module

Architecture Overview

forever uses a monitor/worker pattern. The CLI spawns a monitor process that watches the child script. When the child exits, the monitor evaluates the exit code and restart policy, then re-spawns if appropriate. Each managed process gets its own log files for stdout and stderr. The monitor communicates over IPC to the CLI for commands like list, stop, and restart. A shared socket file tracks all active forever processes on the system.

Self-Hosting & Configuration

  • Install globally: npm install -g forever
  • Start a script: forever start --minUptime 1000 --spinSleepTime 1000 app.js
  • Set custom log output: forever start -o out.log -e err.log app.js
  • Use a JSON config file for multiple processes: forever start forever.json
  • Set the --uid flag to give processes a unique identifier for management

Key Features

  • Zero-downtime restarts with configurable minimum uptime thresholds
  • Per-process log file management with rotation support
  • JSON-based configuration for managing multiple processes
  • Programmatic API for embedding in custom deployment scripts
  • Spin-sleep delay to prevent rapid restart loops on persistent failures

Comparison with Similar Tools

  • PM2 — more feature-rich with clustering, metrics, and a dashboard; forever is simpler and lighter
  • nodemon — restarts on file changes during development; forever restarts on crashes in production
  • systemd — OS-level service manager; forever is Node.js-specific and easier to set up for Node apps
  • Docker restart policies — container-level restarts; forever works inside or outside containers

FAQ

Q: How do I see all running forever processes? A: Run forever list to see process IDs, uptimes, and log file locations.

Q: Can I limit how many times a script restarts? A: Yes. Use --max to set a maximum restart count: forever start --max 5 app.js.

Q: Does forever support clustering? A: No. For clustering, consider PM2 or use the Node.js cluster module directly. forever focuses on single-process monitoring.

Q: Can I use forever with non-Node scripts? A: Yes. Use forever start -c python my_script.py with the -c flag to specify the command interpreter.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires