Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Child process management. Support to create, manage, interact between child process.
Wrapping require("child_process")
module. Supporting to manage child process status such as start,
stop. Handle message, exit status, request/response between parent and child.
npm install partner
var partner = require("partner");
Handling start event.
start
start event.
function(data, master)
is a callback function.
data
Start argument.master
false it is child process otherwise callback is invoked from partner.start([data], [function(error, data){ }])
done(error, data)
callback notify to master.Handling stop event.
stop
stop event.
function(data, master)
is a callback function.
data
Stop argument.master
false it is child process otherwise callback is invoked from partner.stop([data], [function(error, data){ }])
done(error, data)
callback notify to master.Handling message.
message
message event.
function(message, data, master)
is a callback function.
message
Message name.data
Data payloadmaster
false it is child process otherwise callback is invoked from partner.send(message, data, [sendHandle])
function(message, data, response){ }
)Handling request from parent
function(message, data, response)
is a callback function.
message
Message name.data
Data payloadresponse
Callback function(error, data). Invoke to send response to parent.Request parent handle.
message
Message name.data
Data payloadfunction(error, message, data)
is a callback function.modulePath
, [strategy])Asking parent dispatches request/message from other children.
module
Module file path to handle request.strategy
Strategy for select partner to handle. There are: "first", "last", "next", "random", index-numbervar friend = partner.with("modulePath", [strategy])
friend.request(message, data, function(error, message, data)){ }
) Request handlefriend.send(message, data, [sendHandle])
Send message.friend.register(function(message, data) { ... })
Register handle message.friend.unRegister(function(message, data) { ... })
Unregister handle message.modulePath
, [strategy]);Select a child by file path and request handle with strategy.
module
Module file path to handle request.strategy
Strategy for select partner to handle. There are: "first", "last", "next", "random", index-numbervar child = partner.select("modulePath", [strategy])
child.request(message, data, function(error, message, data)){ }
) Request handlechild.send(message, data, [sendHandle])
Send message.Sending message. If itself is child process then send back to parent, otherwise raise "message" event for itself.
message
Message in string format.data
Data payload.Sending message for all children process.
message
Message in string format.data
Data payload.Sending current process. If itself is child process then do nothing, otherwise raise "stop" event for itself.
data
Optional data payload.Start current process. If itself is child process then do nothing, otherwise raise "start" event for itself.
data
Optional data payload.List all children process.
modulePath
): objectCreate child process with JavaScript file path. Return new partner object with methods:
var child = partner.create("./child.js");
child.setOptions(options)
set options for child process like: child_process.fork(modulePath, [args], [options])
.
child.getOptions()
get options.
child.setArguments(args)
set arguments for child process like: child_process.fork(modulePath, [args], [options])
.
child.getArguments()
get arguments.
child.getFile()
get absolute file path.
child.get()
get ChildProcess object.
child.start([data], [callback])
start child process with argument data. Callback if partner invoke done([error],
[data])
child.stop([data], [callback])
stop child process with argument data. Callback if partner invoke done([error], [data])
child.send(message, data, [sendHandle])
send message to child process with data and sendHandler
child.request(message, data, function(error, message, data){ })
request child process message and waiting for
response in callback.
child.broadcast(message, data, [sendHandle])
send message to all children process except itself with data and
sendHandler.
child.exit()
force child process must stop.
child.on("message", function(message, data){} )
handle message event is sent back from child.
child.on("exit", function(errors, data){} )
handle exit event if child is kill or die. Data is start data.
child.handle(function(message, data, response){ })
handle request from child.
var partner = require("./index");
var child = partner.create("master.js");
/* Handle child message. */
child.on("message", function (message, data) {
/* Go message from child. */
console.log("------------------------------");
console.log("[Child::Message]: Got message from child: " + (JSON.stringify({
message: message,
data: data
})));
});
/* Handle child exit. */
child.on("exit", function (errors, data) {
/* Go message from child. */
console.log("[Child::Exit]: Child is killed. Start again with arguments: " + (JSON.stringify(data)));
/* Start again. */
this.start(data);
console.log("------------------------------");
});
/* Handle child request. */
child.handle(function (message, data, response) {
/* Go request from child. */
console.log("[Master::Request]: Got request from child: " + (JSON.stringify({
message: message,
data: data
})));
switch (message) {
case "Multiply":
response(null, data.first * data.second);
default:
response("Master don't handle it!");
}
});
/* Handle start event. */
partner.on("start", function (data, master) {
if (master) {
console.log("[Start]: I'm master: " + (JSON.stringify(data)));
/* Start child if itself is master. */
child.start("Child::Start");
/* Send message to child. */
child.send("Hello", "How are you?");
console.log("------------------------------");
/* Request message to child process. */
child.request("Sum", {
first: 1,
second: 2
}, function (error, message, data) {
console.log("------------------------------");
if (error != null) {
console.error("[" + message + "::Master::Response]: Got error: " + error);
}
console.log("[" + message + "::Master::Response]: " + (JSON.stringify({
message: message,
data: data
})));
});
/* Request message to child process with no handle. */
child.request("NoHandler", "Data", function (error, message, data) {
console.log("------------------------------");
if (error != null) {
console.error("[" + message + "::Master::Response]: Got error: " + error);
}
console.log("[" + message + "::Master::Response]: " + (JSON.stringify({
message: message,
data: data
})));
});
/* Stop entry point after 6 second. */
setTimeout(function () {
console.log("------------------------------");
partner.stop("Master::Stop");
}, 3000);
/* Kill child after 2 second. */
setTimeout(function () {
console.log("------------------------------");
console.log(" child.get().kill()");
child.get().kill();
}, 2000);
} else {
console.log("[Start]: I'm child: " + (JSON.stringify(data)));
/* Send to itself . */
console.log("------------------------------");
partner.send("???", "Who am I?");
/* Ask master request. */
partner.request("Multiply", {
first: 10,
second: 10
}, function (error, message, data) {
console.log("------------------------------");
if (error != null) {
console.error("[" + message + "::Child::Response]: Got error: " + error);
}
console.log("[" + message + "::Child::Response]: " + (JSON.stringify({
message: message,
data: data
})));
});
/* Request message to child process with no handle. */
partner.request("Reject", "Data", function (error, message, data) {
console.log("------------------------------");
if (error != null) {
console.error("[" + message + "::Child::Response]: Got error: " + error);
}
console.log("[" + message + "::Child::Response]: " + (JSON.stringify({
message: message,
data: data
})));
});
}
});
/* Handle stop event. */
partner.on("stop", function (data, master) {
if (master) {
/* Stop child if itself is master. */
child.stop("Child::Stop");
console.log("[Stop]: I'm master: " + (JSON.stringify(data)));
/* Stop child after 1 second. */
setTimeout(function () {
console.log("------------------------------");
console.log(" child.stop('Child::Stop')");
child.stop("Child::Stop");
}, 2000);
/* Force kill child after 3 second. */
setTimeout(function () {
console.log("------------------------------");
console.log(" child.exit()");
child.exit();
}, 3000);
} else {
console.log("[Stop]: I'm child: " + (JSON.stringify(data)));
}
});
/* Handle message event. */
partner.on("message", function (message, data, master) {
if (master) {
console.log("[Message]: Got message from itself: " + (JSON.stringify({
message: message,
data: data
})));
} else {
console.log("[Message]: Got message from parent: " + (JSON.stringify({
message: message,
data: data
})));
}
});
/* Handle default request */
partner.handle(function (message, data, response) {
/* Go request from child. */
console.log("[Child::Request]: Got request from parent: " + (JSON.stringify({
message: message,
data: data
})));
switch (message) {
case "Sum":
response(null, data.first + data.second);
default:
response("I don't handle it!");
}
});
/* Start entry point. */
partner.start("Master::Start");
MIT
FAQs
Child process management. Support to create, manage, interact between child process.
The npm package partner receives a total of 338 weekly downloads. As such, partner popularity was classified as not popular.
We found that partner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.