Piping2
raw JSON → 0.4.1 verified Fri May 01 auth: no javascript maintenance
Piping2 is a hot-reload utility for Node.js that automatically restarts your application when files change, without requiring a wrapper binary. Version 0.4.1 is the latest stable release. Unlike nodemon or node-supervisor, it uses the cluster API to spawn your app in a worker process, enabling clean restarts without external daemons. It supports transpiler integration (e.g., Babel), file watching via chokidar, and optional require hook for selective monitoring. This package is considered unstable and intended for development only. Note that piping2 is a fork of the original piping package, with no active maintenance.
Common errors
error TypeError: piping is not a function ↓
cause Importing piping2 using ESM `import piping from 'piping2'` fails because the module exports a CommonJS function.
fix
Use
const piping = require('piping2') error Your application code runs twice. Please check your piping setup. ↓
cause Not guarding application logic with the `if (piping()) { ... }` pattern, so code executes in both master and worker processes.
fix
Wrap your app code with
if (!require('piping2')()) { return; } error Error: ENOENT: no such file or directory, watch ... ↓
cause File watching fails because the specified 'main' path does not exist or is incorrect.
fix
Ensure the 'main' option points to an existing file, e.g.,
./server.js Warnings
breaking Unstable cluster API used; crashes may occur on some Node versions. ↓
fix Consider switching to nodemon or supervisor for production stability.
gotcha Your file is invoked twice: first by the master process (returns false), then by the worker (returns true). ↓
fix Always wrap application logic in an `if (piping()) { ... }` block or guard with `return`.
gotcha If 'hook' is false (default), all files in the main file's directory are watched. Use 'ignore' to exclude node_modules. ↓
fix Set `hook: true` to only watch required files, but note that files required before piping() are not tracked.
breaking Depends on chokidar, which may have breaking changes between major versions. ↓
fix Pin chokidar version in your project's package.json if issues arise.
Install
npm install piping2 yarn add piping2 pnpm add piping2 Imports
- default (function) wrong
import piping from 'piping2'correctconst piping = require('piping2') - piping() with options object wrong
const { piping } = require('piping2')correctrequire('piping2')({ main: './server.js', hook: true }) - piping() with string argument wrong
require('piping2').default('./server.js')correctrequire('piping2')('./server.js')
Quickstart
const piping = require('piping2');
if (!piping({ main: './app.js', hook: false })) { return; }
console.log('App hot-reloading with piping2!');