Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 7, 2026·3 min de lectura

forever — Keep Node.js Scripts Running Continuously

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

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
forever Overview
Comando de instalación directa
npx -y tokrepo@latest install 118e56f4-799e-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con 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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados