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 🙏

© 2024 – Pkg Stats / Ryan Hefner

noder-restart

v1.1.3

Published

Node script runner with self-restarting

Downloads

3

Readme

noder: node + restart

Simple node script that allows you to run scripts which are able to self-restart, self-terminate and run forever.

NPM

How does it work?

noder listens to special directives on stdout stream. When the script wants to be restarted, it simply console.log a directive like [noder:restart]. Then noder catches it and restarts the script. So simple, isn't it?

Installation

# GLOBAL
$ npm i -g noder-restart # using npm...
$ yarn global add noder-restart # ...or yarn

# LOCAL
$ npm i -D noder-restart
$ yarn add -D noder-restart

Usage

Save this script as script.js:

console.log('Hello World!');

setTimeout(() => {
  console.log('Restarting...');
  console.log('[noder:restart]'); // [noder:restart] will be caught by noder and will cause the script to restart

  // You can write everything in one line as well:
  // console.log('Restarting... [noder:restart]');
}, 1000);

Then run it using noder:

$ noder script.js

Or, if you installed noder locally:

$ npx noder script.js
$ yarn noder script.js

The script will be restarted every second.


console.log('[noder:restart]'); - restarts script
console.log('[noder:terminate]'); - terminates script

Safe console

You can enable safe console mode in the script run by noder. This mode prevents terminate/restart by accident by removing the directives from the stream while using console.log.

Here's how to enable safe console:

const { enableSafeConsole } = require('noder-restart');

// Enable safe console mode
// Note: if you configure noder to use custom terminate/restart directive
// you will need to change the directives below. Otherwise leave everything as is.
const terminator = enableSafeConsole({
  restart: '[noder:restart]',
  terminate: '[noder:terminate]'
});

// Now if you type:
console.log('[noder:restart]');
console.log('[noder:terminate]');
// nothing happens!

// Use terminator object to restart script
terminator.restart();

// In case you want to terminate your script, write:
// terminator.terminate();

Note: You should install noder as a normal (not dev) dependency if you want to use safe console (don't add -D flag to the npm i/yarn add command).

CLI

Usage: noder [options] <script> [script args]

Options:

  • -h, --help - Displays noder's help
  • -v, --version - Displays noder's version
  • -f, --forever - Enables forever mode (it means the script will restart after crash/exit; you can quit it by terminating)
  • -w, --watch - Defines glob patterns for watch mode
  • -N, --no-node - Disables node script execution mode (you can execute every script/program)
  • -c, --config - Loads custom config file (the default one is /current/working/dir/noder.json if exists)
  • --restart - Defines custom restart directive
  • --terminate - Defines custom terminate directive

Config

By default noder searches for the config file named noder.json placed in the current working directory (you can change it using -c/--config option).

Content:

{
  "file": "script.js",
  "args": ["arg1", "arg2"],
  "forever": false,
  "watch": ["*.js", "*.ts"],
  "noNode": false,
  "directives": {
    "restart": "[noder:restart]",
    "terminate": "[noder:terminate]"
  }
}
  • file - node script to execute (or the program name/path if noNode is true)
  • args - CLI arguments for script/program
  • forever - forever mode (auto-restart after exit/crash)
  • watch - array with glob patterns for watch mode
  • noNode - disable node (runs every program; the path to program must be provided in file)
  • directives - list of directives
    • restart - restart directive
    • terminate - terminate directive