Is each node call run its own version of node - javascript

If i run app by node index.js and then i do it again before the first process finishes. Do each call have it´s own separate nodejs instance with it´s own call stack?
What is the overheas of doing this?

Indeed, each run gets its own process, you will not be able to link the processes in a normal way.
Furthermore, if both processes listen to the same port, the second run will fail with an error:
Error: listen EADDRINUSE: address already in use

Related

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

Capture Command line response in an Electron/NodeJS app

I need to execute command line commands from an ElectronJS App which also has NodeJS available and then capture the response from those commands ran.
The Xampp Windows WAMP Dev Server app shown below has an example of capturing the command response and showing it in an app.
How can I do this in a NodeJS/ElectronJS app?
You can use the module Child Proccess using the method exec. The documantation for it is pretty clear and can be seen in this link: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
The command line response will be in the stdout parameter of the callback function.

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

MONGO_URL for running multiple Meteor apps on one server

I have one Meteor application running on my Ubuntu server (Digital Ocean). I use Meteor Up (MUP) to deploy and keep the app running. Everything works fine.
However, when I try to deploy a second app on the same server, something goes wrong in connecting to the MongoDB. I get a long and unreadable error message that starts "Invoking deployment process: FAILED" and then ends with
Waiting for MongoDB to initialize. (5 minutes)
connected
myapp start/running, process 25053
Waiting for 15 seconds while app is booting up
Checking is app booted or not?
myapp stop/waiting
myapp start/running, process 25114
And the app refuses to run. I have tried a number of things to fix this and will edit this post if more info is requested, but I'm not sure what's relevant. Essentially I don't understand the Error message, so I need to know what the heck is going on?
EDIT:
I want to add that my app runs fine if I go into the project folder and use the "meteor" command. Everything runs as expected. It is only when I try to deploy it for long-term production mode with MUP that I get this error.
EDIT:
I moved on to trying mupx instead of mup. This time I can't even get past the installation process, I get the following error message:
[Neal] x Installing MongoDB: FAILED
-----------------------------------STDERR-----------------------------------
Error response from daemon: no such id: mongodb
Error: failed to remove containers: [mongodb]
Error response from daemon: Cannot start container c2c538d34c15103d1d07bcc60b56a54bd3d23e50ae7a8e4f9f7831df0d77dc56: failed to create endpoint mongodb on network bridge: Error starting userland proxy: listen tcp 127.0.0.1:27017: bind: address already in use
But I don't understand why! Mongod is clearly already running on port 27017 and a second application should just add a new database to that instance, correct? I don't know what I'm missing here, why MUP can't access MongoDB.
It's tricky without your mup.json to see what's going on here. Given what you said, it looks like your 2nd app deployment tries to override/boot mongodb over the 1st one which is locked, the mongodb environment fails to boot, causing then the fail. You should tackle this different ways:
If your objective is to share your mongoDB, point the MONGO_URL from your 2nd mup.jon on your first mongodb instance. It's generally something along the 2701X ports. As it's a shared DB, changes in one database could affect the other.
meteor-up oversees the deployment of your app from a meteor-nice-to-test thing to a node+mongodb environment. You can spawn another mongod instance with :
mongod --port 2701X --dbpath /your/dbpath --fork --logpath /log/path on your DO server and then point MONGO_URL there.
Last but not least, mupx having docker under the hood. Using mupx for your deployments should isolate both apps from each other.

Node.js why does a child process not start right away?

I'm trying to write a global node command line program that will take any (windows or unix) console command I give to it and execute it in a new console window. I also want the program to exit after it has spawned its process so the console I'm using isn't blocked by a node script that has a child process running.
This is a simple version of what I have so far:
myScript.js:
var exec = require('child_process').exec;
exec("start startScript.cmd"); // windows start command opens a new cmd window
process.exit(0);
startScript.cmd:
mkdir test
I have also tried this (But this doesn't work even without the process.exit):
myScript.js:
var spawn = require('child_process').spawn;
var child = spawn('start', ['startScript.cmd'], { detached: true, stdio: ['ignore', 'ignore', 'ignore']});
child.unref();
process.exit(0);
The problem is, calling process.exit() seems to prevent the child process from fully starting and so nothing happens unless I do some setTimeout shenanigans. However the behavior seems random. On a different computer it behaves like I want it to. Both computers have the same version of node (v0.10.33).
The directory test is never made unless I remove the process.exit line or use a setTimeout on it.
Any idea why this happens or how to get around it? Keep in mind I don't want to wait until the child process is finished. I want to be able to return to my command line immediately.
Thanks!
I figured it out.
The answer is: don't use exec and don't use start or call or any other weird windows command in the spawn call. Set the CWD if need be in the spawn options and either spawn what you want directly or make a OS specific script that calls your command if it still isn't working. One example of a windows script is literally just:
%*
That way, start or any other weird windows command will be executed correctly (but do you really need them?).

Categories