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

@omarty13/node-reloader

v2.7.1

Published

**Node Reloader** was created for convenient start of child process and its restart in case of failure or change of source files. This is version without any dependencies. Only native node modules.

Downloads

10

Readme

node-reloader

Node Reloader was created for convenient start of child process and its restart in case of failure or change of source files. This is version without any dependencies. Only native node modules.

Install

npm install @omarty13/node-reloader

Parameters

  • scriptPath {String} - Full path of the script.
  • spawnOptions {Object} - Spawn options.
    • cwd {String} | {URL} Current working directory of the child process.
    • env {Object} Environment key-value pairs. Default: process.env.
    • argv0 {String} Explicitly set the value of argv[0] sent to the child process. This will be set to command if not specified.
    • stdio {Array} | {String} Child's stdio configuration (see options.stdio).
    • detached {Boolean} Prepare child to run independently of its parent process. Specific behavior depends on the platform, see options.detached).
    • uid {Number} Sets the user identity of the process (see setuid(2)).
    • gid {Number} Sets the group identity of the process (see setgid(2)).
    • serialization {String} Specify the kind of serialization used for sending messages between processes. Possible values are 'json' and 'advanced'. See Advanced serialization for more details. Default: 'json'.
    • shell {Boolean} | {String} If true, runs command inside of a shell. Uses '/bin/sh' on Unix, and process.env.ComSpec on Windows. A different shell can be specified as a string. See Shell requirements and Default Windows shell. Default: false (no shell).
    • windowsVerbatimArguments {Boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to true automatically when shell is specified and is CMD. Default: false.
    • windowsHide {Boolean} Hide the subprocess console window that would normally be created on Windows systems. Default: false.
    • signal {AbortSignal} allows aborting the child process using an AbortSignal.
    • timeout {Number} In milliseconds the maximum amount of time the process is allowed to run. Default: undefined.
    • killSignal {String} | {integer} The signal value to be used when the spawned process will be killed by timeout or abort signal. Default: 'SIGTERM'.
  • watch {Array} - Watch changes in files for reload child process. File, dir, glob.
  • ignore {Array} - Optional. File/paths ignored for watching. File, dir, glob.
  • args {String[]} - Optional. Arguments for execution script.
  • autostart {Boolean} - Optional. Autostart after creating Nodereloader. Default true.
  • restartTimeout {Number} - Optional. Restart timeout (milliseconds) after shutdown process with error. Default 3000 ms.
  • watcherDelay {Number} - Optional. The delay (milliseconds) between successful spawn the process and creating the watcher after. Default 1000 ms.
  • beforeStart {Function} - Optional. The function is called before start.
  • beforeRestart {Function} - Optional. The function is called before restart.

Functions

start()

  • Start NodeReloader. Use for manual start then autostart parameter set in false.

stop()

  • Stop NodeReloader.

restart()

  • Restart NodeReloader.

Example of use

import path                             from 'node:path';
import { fileURLToPath }                from 'node:url';
import NodeReloader                     from '@omarty13/node-reloader';

const __dirname = path.dirname(fileURLToPath(import.meta.url));


let nodeReloader = new NodeReloader({
	// Path to the node.js
	nodePath: "node", // By default is "node", but can be used for example - "c:/Program Files/nodejs/node.exe"
	// Path of the script
	scriptPath: __dirname + "/app-test.js",
	// Spawn options
	spawnOptions: {
		stdio: [ process.stdin, process.stdout, process.stderr, 'ipc', ],
		// cwd: __dirname +"/src",
		// ...
	},
	// Delay before watch
	watcherDelay: 0,
	// Arguments for pass to process
	args: [
		// `--base-dir=${"BASEDIR"}`,
	],
	// Watch changes in files for reload child process
	watch: [
		__dirname + "/dir-to-test/**/*-?.mjs",
		__dirname + "/dir-to-test/*.json",
	],
	// Ignore changes in files
	ignore: [
		// __dirname + "/dir-to-test/*.js",
	],
	// Autostart of watching (Default: true)
	autostart: true,
	// Delay before restart  (Default: 3000)
	restartTimeout: 5000,
	// The function is called before start
	beforeStart: async ({ pathnamesToWatch, }) => {
		console.log("Call before start node instance.");
		// pathnamesToWatch - Array with pathnames of files to watch.
	},
	// The function is called before restart
	beforeRestart: async ({ filesChanged, }) => {
		onsole.log("Call before restart node instance.");
		// filesChanged - Array with data of files to watch like [{ eventType, filename, pathname, }, { eventType, filename, pathname, }, ...]
	},
});