Skip to content

Instantly share code, notes, and snippets.

View ndelangen's full-sized avatar
🇳🇱
yes?

Norbert de Langen ndelangen

🇳🇱
yes?
  • Chroma Software
  • Netherlands
View GitHub Profile
@ndelangen
ndelangen / spawn-node-ipc.js
Created January 2, 2017 15:01
Spawn can be used to create a process from any command.
const spawn = require('child_process').spawn;
const command = 'node';
const parameters = [path.resolve('program.js')];
const child = spawn(command, parameters, {
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ]
});
@ndelangen
ndelangen / child.js
Last active December 5, 2022 18:38
NodeJS child_process communication (IPC) example
if (process.send) {
process.send("Hello");
}
process.on('message', message => {
console.log('message from parent:', message);
});
@ndelangen
ndelangen / add-ipc-communication-fork.js
Last active January 2, 2017 14:40
To communicate with the child process we need to enable.
const fork = require('child_process').fork;
const program = path.resolve('program.js');
const parameters = [];
const options = {
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ]
};
const child = fork(program, parameters, options);
@ndelangen
ndelangen / silent-fork-process.js
Created January 2, 2017 14:22
A simple way to just create a silent child process is to pass a options object and set the `silent` property
const fork = require('child_process').fork;
const program = path.resolve('other.js');
const child = fork(program, [], {
silent: true
});
@ndelangen
ndelangen / simple-fork-example.js
Created January 2, 2017 14:20
Fork can spawn a new NodeJS process. You give it a javascript file to execute.
const fork = require('child_process').fork;
const program = path.resolve('other.js');
const child = fork(program);
(function ($) {
var elements = {
html: document.documentElement
body: document.body
};
$(elements.body).one('touchstart', function () {
$(elements.body).off('mouseenter.cursor-detection');
});
$(elements.body).one('mouseenter.cursor-detection', function () {