https://github.com/jadbox/node-box
Loads Node.js modules into a non-blocking child-processes with messaging passing.
https://github.com/jadbox/node-box
Last synced: 12 days ago
JSON representation
Loads Node.js modules into a non-blocking child-processes with messaging passing.
- Host: GitHub
- URL: https://github.com/jadbox/node-box
- Owner: jadbox
- Created: 2014-12-20T01:00:52.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-21T19:33:05.000Z (over 11 years ago)
- Last Synced: 2025-03-04T07:32:12.562Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://twitter.com/jadbox
- Size: 203 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node-Box
By: Jonathan Dunlap
12/21/2014
This is a Node library that dynamically loads module JS files and uses a two-way communication channel. Each client module runs in its own complete and sandboxed process, and it is blocking-free from other running modules.
## Features
- Runs each module in its own Node process
- Client modules are proper child-processes to the host, aiding monitoring and debugging.
- Modules have a full node environment, including stdout.
- Modules run in a complete isolated environment and cannot conflict in local or global namespaces.
- Modules and Host can communicate bi-directionally
- Modules can throw errors to the host.
- The host can directly start and kill modules dynamically.
## Example
For a full example see [example/main.js](https://github.com/jadbox/node-box/blob/master/example/main.js)
Example Host:
```javascript
// Instance the BoxHost to load clients
var host = new BoxHost();
// Load and start Game2.js module
// Register the file to ID 'game2'
// Register the error handler onError
host.start('game1', __dirname + '/Game1.js', onError);
// Register message handler
host.on('game1', function(msg) { } );
// Call client module handler with parameters:
host.send('game1', 'callMe', [2, true]);
// Kill the client, as it will continue to run otherwise.
host.kill('game1');
```
Example Client (file: Game1.js):
```javascript
// Set the API handles
var api = {
'callMe':callMe
}
// Instance the client lib with the API handles
var client = new BoxClient(api);
// Send a message to the host
client.send("Hello Host!");
// Send an error message to the host
client.throw("!!!false alarm!!!");
// This handle gets called for host messages
function callMe(a) {
console.log("Game1 was called with one param: " + a);
}