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.
make node.js get power of multi-process.
Be cautious if you want to use it in your real projects.
As we all know, JavaScript, running in a single main process environment, can deal some specific jobs with another process. Unfortunately we can not create any child process directly.
Thank to the child_process
module provided by Node.js
, we are able to create child processes by shell commands. The most special one, child_process.fork
, can be used to create child processes by JavaScript files.
The trouble is we have to leave the function of the child process an individual file and use the message
mechanism to receive values from the child process. That's not really cool.
Image what if we create a child process as easy as creating a Promise
object, how fantastic it will be.
The hyber
function will add some details, tranform your function into temporary file and call it.
Suppose you give a function like this
function add(a, b) {
return a + b
}
Then it will be transformed to
`(function add(a, b) {
return a + b
})(arg1, arg2)
`
Once you give the arguments, they will be filled into the string like
;`(function add(a, b) {
return a + b
})(10, 20)
`
Send message to the main process
`const value = (function add(a, b) {
return a + b)
})(10, 20)
process.send(value)
`
Eventually, fork the file and handle the message by Promise.
That's it.
import hyber from 'hyber'
npm install hyber
# or
yarn add hyber
const func = () => 10
const asyncFunc = hyber(func)
// 10
const result = await asyncFunc()
hyber
generates a new function, you should pass the arguments into the new one.
const func = a => a + 10
const asyncFunc = hyber(func)
// 30
const result = await asyncFunc(20)
Since the new function generated by hyber
runs in a completely different process, it can not capture any variables in the current process. You have to pass all variables as arguments.
Use it only if you want to do tons of calculations without blocking the main process.
FAQs
make node.js get power of multi-process.
The npm package hyber receives a total of 0 weekly downloads. As such, hyber popularity was classified as not popular.
We found that hyber 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.