Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
electron-workers
Advanced tools
Run electron scripts in managed workers
This module let you run an electron script with scalability in mind, useful if you have to rely on electron to do heavy or long running tasks in parallel (web scrapping, take screenshots, generate PDF, etc)
script.js
var http = require('http'),
app = require('app');
// every worker gets unique port, get it from a process environment variables
var port = process.env.ELECTRON_WORKER_PORT,
host = process.env.ELECTRON_WORKER_HOST;
app.on('ready', function() {
// you can use any webserver library/framework you like (connect, express, hapi, etc)
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
// data passed to `electronWorkers.execute` will be available in req body
req.pipe(res);
});
server.listen(port, host);
});
var electronWorkers = require('electron-workers')({
pathToScript: 'script.js',
timeout: 5000,
numberOfWorkers: 5
});
electronWorkers.start(function(startErr) {
if (startErr) {
return console.error(startErr);
}
// `electronWorkers` will send your data in a POST request to your electron script
electronWorkers.execute({ someData: 'someData' }, function(err, data) {
if (err) {
return console.error(err);
}
console.log(JSON.stringify(data)); // { someData: 'someData' }
});
});
pathToScript
(required) - path to the electron script
pathToElectron
- path to the electron executable, by default we will try to find the path using the value returned from electron-prebuilt
or the value in your $PATH
electronArgs
Array - pass custom arguments to the electron executable. ej: electronArgs: ['--some-value=2', '--enable-some-behaviour']
timeout
- execution timeout in ms
numberOfWorkers
- number of electron instances, by default it will be the number of cores in the machine
host
- ip or hostname where to start listening phantomjs web service, default 127.0.0.1
portLeftBoundary
- don't specify if you just want to take any random free port
portRightBoundary
- don't specify if you just want to take any random free port
hostEnvVarName
- customize the name of the environment variable passed to the electron script that specifies the worker host. defaults to ELECTRON_WORKER_HOST
portEnvVarName
- customize the name of the environment variable passed to the electron script that specifies the worker port. defaults to ELECTRON_WORKER_PORT
If you are using node with nvm and you have installed electron with npm install -g electron-prebuilt
you probably will see an error or log with env: node: No such file or directory
, this is because the electron executable installed by electron-prebuilt
is a node CLI spawning the real electron executable internally, since nvm don't install/symlink node to /usr/bin/env/node
when the electron executable installed by electron-prebuilt
tries to run, it will fail because node
won't be found in that context..
Solution:
1.- Install electron-prebuilt
as a dependency in your app, this is the option recommended because you probably want to ensure your app always run with the exact version you tested it, and probably you dotn't want to install electron globally in your system.
2.- You can make a symlink to /usr/bin/env/node
but this is not recommended by nvm authors, because you will loose all the power that nvm brings.
3.- Put the path to the real electron executable in your $PATH
.
See license
FAQs
Run electron scripts in managed workers
The npm package electron-workers receives a total of 86 weekly downloads. As such, electron-workers popularity was classified as not popular.
We found that electron-workers 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.