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 🙏

© 2025 – Pkg Stats / Ryan Hefner

script-manager

v0.10.2

Published

Manager for running foreign and potentionally dangerous scripts in the cluster

Downloads

7,612

Readme

script-manager

NPM Version License Build Status

node.js manager for running foreign and potentially dangerous scripts in the cluster

Basics

You can use node.js vm module for running a custom javascript code, but when the code is bad it can quickly get your node.js process into an endless loop. For this reason it is better to run users's custom code in a separate node process which you can recycle when the script reaches timeout. This can be achieved using node child_process module, but a simple implementation has limitations in performance and scale because running each script in a new node child process can quickly spawn whole system with node processes. This package solves the problem of running user's custom javascript code in a load balanced cluster of node processes which are reused over the requests and recycled when needed.

var path = require('path')
var scriptManager = require("script-manager")({ numberOfWorkers: 2 });

scriptManager.ensureStarted(function(err) {

	/*send user's script including some other specific options into
	wrapper specified by execModulePath*/
	scriptManager.execute({
		script: "return 'Jan';"
	}, {
		execModulePath: path.join(__dirname, "script.js"),
	    timeout: 10
	}, function(err, res) {
		if (err) {
			return console.error('Error:', err)
		}

		console.log(res);
	});

});
/*script.js
wrapper usually does some fancy thing and then runs the custom script using node.js vm module*/
module.exports = function(inputs, callback, done) {
	var result = require('vm').runInNewContext(inputs.script, {
		require: function() { throw new Error("Not supported"); }
	});
	done(null result);
};

Callbacks

The executing script can also callback to the caller process. The callback is provided using node.js cross process messages so it has some limitations, but should work when transferring just common objects in parameters.

To provide caller callback you can add the callback property to the execute options:

scriptManager.execute({
		script: "return 'Jan';"
	}, {
		execModulePath: path.join(__dirname, "script.js"),
	    callback: function(argA, argB, cb) {
		    cb(null, "foo");
	    }
	}, function(err, res) {
		console.log(res);
	});

Then in the wrapper you can for example offer a function funcA to the users script which uses callback parameter to contact the original caller.

module.exports = function(inputs, callback, done) {
	var result = require('vm').runInNewContext(inputs.script, {
		require: function() { throw new Error("Not supported"); },
		funcA: function(argA, cb) {
			callback(argA, cb);
		}
	});
	done(result);
});

Options

var scriptManager = require("script-manager")({
 		/* number of worker node.js processes */
		numberOfWorkers: 2,
		/* set a custom hostname on which script execution server is started, useful is cloud environments where you need to set specific IP */
		host: '127.0.0.1',
		/* set a specific port range for script execution server */
		portLeftBoundary: 1000,
		portRightBoundary: 2000,
		/* maximum size of message sent/received from/to worker in http-server strategy, pass -1 to have no limit*/
		inputRequestLimit: 200e6,
		/* switch to use dedicated process for script evalution, this can help with
		some issues caused by corporate proxies */
		strategy: "http-server | dedicated-process | in-process",
		/* options passed to forked node worker process: { execArgv: ['�-max-old-space-size=128'] } */
		forkOptions: {}
	});

License

See license