GithubHelp home page GithubHelp logo

tkodev / lib-instance-control Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 98 KB

๐Ÿ”Œ Instance Control - A NPM module to wrap around node's child process spawn functions.

License: MIT License

JavaScript 100.00%

lib-instance-control's Introduction

Instance Control

  • ๐Ÿ” Instance Control - A NPM module to wrap around node's child process spawn functions.
    • Just a wrapper to start and stop process instances.
    • Not for public production! Please fork for personal use! - This module is for @htkoca's private development.

Usage Summary

  • Prep: Load the module
  • Step 1: Instance creation and termination
  • Step 2: General instance functions

Prep

Let's install the module

  • in terminal: npm install instance-control

Step 1

Instance creation and termination

// dependencies
const InstanceCtrl = require('instance-control')

// create new controller
let instanceCtrl = new InstanceCtrl();

// start new child instances with name string, returns node native <ChildProcess>
let subProcess = instanceCtrl.startInstance('nodeApp', `node example-process.js`)
let subProcess2 = instanceCtrl.startInstance('nodeApp', `node example-process.js`)

// let's get a console log when process exited
subProcess.on('exit', (code, signal) => {
	console.log(`subProcess exited with code: '${code}', signal: '${signal}'`);
});

// get all instances under 'nodeApp' child name, returns: array of <ChildProcess>'s
let instances = instanceCtrl.getInstances('nodeApp');

// kill all instances under 'nodeApp' child name, returns: true if any kill signal sent
let killStatus = instanceCtrl.killInstances('nodeApp');

Step 2

General instance functions

// start another instance to test global functions
instanceCtrl.startInstance('nodeApp', `node example-process.js`);

// get all instances, returns: object with child name as property, process arrays as value
let allInstances = instanceCtrl.getAll();

// kill all instances, returns: object with child name as property, process arrays as value
let killStatusAll = instanceCtrl.killAll();

Step 3

Single instance functions - promise based

// start only one process - each command kills previous app
(async function() {
  let subProcess = await instanceCtrl.singleInstance('nodeApp', `node example-process.js`);
	let subProcess2 = await instanceCtrl.singleInstance('nodeApp', `node example-process.js`);
	let subProcess3 = await instanceCtrl.singleInstance('nodeApp', `node example-process.js`);
	console.log(subProcess3);
})();

lib-instance-control's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.