How to fork a child process with electron - javascript

I have a simple nodeJS app that has a function to scrape file metadata. Since scraping metadata can be intensive I made the app run this as a child process using fork.
const metaParser = child.fork( fe.join(__dirname, 'parse-metadata.js'), [jsonLoad]);
Everything worked great until I ported this to electron. When run in main.js the process is successfully created, but immediately exits. I added some logging to parse-metadata.js and found out that parse-metadata.js executed successfully and ran long enough to run the first few lines of code and then exited.
How do I get electron to fork parse-metadata.js and keep it alive until the end?
I'm using electron v1.4.15 and Node v6

When using the detached option to start a long-running process, the process will not stay running in the background unless it is provided with a stdio configuration that is not connected to the parent.
Also it seems related to the env.
Look at this: https://github.com/electron/electron/issues/6868

Related

While running npm run build for nextjs app in EC2 instance it is getting killed automatically

I am trying to deploy my nextjs app on EC2 but when I was running npm run build it was getting killed automatically, so I thought it might be because of the ram so I changed my instance type to t3.medium which has 4GB ram but I am still having the same problem.
The optimization takes place because the ec2 instance does not have enough memory for building available for your Next app to run.
Again, the problem will arise only when running the command
$ npm run build
error due to not having enough memory
and not when you start the next app or run the command
$ npm start
should work as too much memory is not needed.
You have already tried increasing the memory (I do not recommend that as you are changing your instance and paying more for a task that you will run only once and that too can be done on any other machine) by changing the instance type. You can try some other ways:
Option 1: You can try to optimize your Next.js app by removing unnecessary dependencies and minimizing the size of your assets.
Option 2: You can try building the Next.js app on another machine (does not have to be Linux) with more memory and then transfer the build to the EC2 instance using ssh or WinSCP.
Option 3: use a service like AWS Elastic Beanstalk - This service automatically handles provisioning, load balancing, and automatic scaling for your Next.js application.
Option 1 may not be practical so I recommend trying option 2 or 3.

Why is Puppeteer not displayed as a child process on IIS?

I have a node.js server which runs a child process on the server when the user requests.
This child process is managed by npm package 'child_process' and running a 'Puppeteer' script.
The whole process works as expected on local.
The problem is when I check it on the server, and then - the process IS executed and logs are printed, BUT I don't see the browser of puppeteer even though it's in headless false.
The server uses IIS and I suspect that maybe it's related.
p.s. I also tried the npm package 'execa' for the execution of the child process, and nothing changed.
Any ideas?
Thanks

Connect to OpenVPN server through Node.js

I’m trying to create a GUI client for connecting to OpenVPN servers using electron and node but I’m struggling to figure out how to actually connect to the servers using the .ovpn files.
My question is what is the best way to connect to an OpenVPN server using node? Would it be best to Tun terminal commands like
“openvpn—config path to config”
Or is there another way applications like tunnelblick do it that might be easier or more efficient?
Hello I have been working with electron and ovpn on my last project, so here are a few tips.
VPNs require admin/root privilege in order to get setup, so running child_process.spawn on openvpn --config <path> will fail unless your electron app is being ran via sudo/admin privilege.
You can also use electron-sudo package, link here. This is basically a child process spawn with sudo/admin. Aka, app runs normally, but vpn command runs with sudo.
However, if your client is sketchy about giving you sudo/admin, the VPN must be ran separately prior to launching your app.
All in all its a admin/sudo thing.
Hope this helps.

Why Nightwatch run every .js file as Child process? (Perhaps i have changed some config)

Lately when i run Nightwtch.js , my console run as child process every file .js of every folder or subfolder as Child process. Multiple chrome instances are open with them too. Even module folder with require js libraries.. I think i m forgetting some config.
I only want to run the main Nightwatch js file with one chrome..
My console prints starting..
nightwatch bot.js -c config_chrome.json
Started child process for: tests/extra/assertions/customAssertion
Started child process for: tests/extra/commands/customCommand
tests/extra/assertions/customAssertion finished.
tests/extra/commands/customCommand finished.
Started child process for: tests/extra/commands/customCommandConstructor
Started child process for: tests/extra/commands/other/otherCommand
tests/extra/commands/customCommandConstructor finished.
Started child process for: tests/extra/globals
tests/extra/globals finished.
Started child process for: tests/extra/otherPageobjects/otherPage
tests/extra/otherPageobjects/otherPage finished.
Started child process for: tests/extra/pageobjects/SimplePageFn
tests/extra/pageobjects/SimplePageFn finished.
Started child process for: tests/extra/pageobjects/invalidPageObj
tests/extra/commands/other/otherCommand finished.
Started child process for: tests/extra/pageobjects/simplePageObj
tests/extra/pageobjects/invalidPageObj finished.
I forget sending --test to console... :)
There's a configuration setting that can cause this behavior as well.
If you've set "test_workers": true in nightwatch.conf.js all of your tests are run in parallel, and this fires up child processes for every file in your the directory where nightwatch runs its tests.
Documentation here:
https://github.com/nightwatchjs/nightwatch-docs/blob/master/guide/running-tests/run-parallel.md

Killing a Node.js program from a shell script

I'm running a node.js application which is acting as a man-in-the-middle proxy to proxy all of the requests I'm making through a PhantomJS headless testing environment. I want to spin up this proxy from either my PhantomJS test script (though I've looked into it and it seems that phantom does not have an exec() command for executing shell commands) or a small shell script which manages both processes. Ideally, it would do something like
#!/bin/bash
node proxy.js
phantomjs runTests.js
kill node process here
Is there any way that I can do this?
Moments after asking this question, I found a much better way to execute the phantom program from within my node app by using a child process. I placed my phantom script within the folder which contained my node app, and then used exec like this:
var exec = require('child_process').exec;
var _phantom = exec('phantomjs runTests.js',function(error,stdout,stderr){
console.log(stdout);
};
_phantom.on('exit',function(code,sig){
process.exit(code);
});
This means I could spin up my proxy server, then execute the child process. The _phantom.on('exit') block allows me to detect when the process exits on a code. Then, it's very simple to signal the node app to quit, using process.exit.

Categories