minimal file watch and restart with opti-node
Last updated 2 years ago by tcrowe .
UNLICENSED · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install opti-node-watch 
SYNC missed versions from official npm registry.


Run opti-node in development with automatic restart.

The idea is to minimize how much system resources node uses and provide a lighter alternative to nodemon.

CLI Usage

Simply opti-node-watch -w dist -d 500 --script dist/index.js

All flags


Watch these directories or files. (required, no default)
-w dist/client
--watch dist/server
-w dist/shared
-w dist/index.js
--watch package.json


Extensions: (optional, default: js,jsx,json)
--ext js,jsx,ts,tsx,json

Use of --ext is comma-separated without spaces.


Reload delay in milliseconds: (optional)
-d 1000
--delay 1000


Command to execute: (optional, default: opti-node)
--exec node
--exec python


Which script to run: (required, no default)
--script dist/index.js


Debug, show which events happen:



Programmatic usage in JS

const path = require('path')
const { createWatcher } = require("opti-node-watch")
const distPath = path.join(__dirname, "dist")
const indexPath = path.join(distPath, "index.js")

const watcher = createWatcher({
  watchPatterns: [distPath],
  script: indexPath

watcher.addListener("error", err => {
  console.log("opti-node-watch error", err)

watcher.addListener("change", evt => {
  const { path, evtType, filename } = evt
  console.log("opti-node-watch change")
  console.log('path', path)
  console.log('evtType', evtType)
  console.log('filename', filename)

// pipe to the process

watcher.addListener("started", () => console.log("opti-node-watch started"));




  • watchPatterns, string[], required, no default
  • restartDelay, number, optional, default 0
  • extensions, string[], optional, default ["js", "jsx", "json"]
  • exec, string, a command to execute
  • script, string, the node script


# create dev build
npm run dev

# create production build
npm run prd

Please run npm run prd before commit! Thanks

Differences from nodemon

I'm sure this has been done a million times now. There were certain aspects of nodemon which were inconvenient to my development process or it simply wouldn't work. I also wanted to see if I can run this with opti-node.

  • Does not use chokidar
  • No json file config e.g. nodemon.json
  • No -e flag for extensions
  • No ignore yet
  • Less options for polling types
  • No triggering other events
  • Less ecosystem around it

Copying, license, and contributing

Copyright (C) Tony Crowe github@tonycrowe.com (https://tcrowe.github.io) 2018

Thank you for using and contributing to make opti-node-watch better.

⚠️ Please run npm run prd before submitting a patch.

⚖️ opti-node-watch is Free Software protected by the GPL 3.0 license. See ./COPYING for more information. (free as in freedom)

Current Tags

  • 0.2.1                                ...           latest (2 years ago)

5 Versions

  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (7)
Dev Dependencies (12)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |