Execute Node.JS terminal commands in a function - node.js

I have a Node.JS file and usually I run it with the terminal command node index.js, but I want to automate it. How would I be able to run that command in a function instead of the terminal?

Related

Can't execute global Node.js module from Bash shell script (Truffle)?

I installed Truffle, the Ethereum development toolkit, on my Ubuntu 14.04 PC. I can execute it easily from a terminal window by simply typing "truffle". However, when I try to execute Truffle from a Bash shell script, I get the following error:
ide-do-truffle.sh: line 3: truffle: command not found
The line inside the shell script is just:
truffle compile --network local
How can I execute Truffle from within a shell script?
If someone can also explain what goes on behind the scenes when you execute a globally installed Node.JS package like Truffle, that would be helpful too.
Its possible the PATH in your terminal window is not the same as the PATH that your shell script sees.
Try echo "$PATH" in both your terminal window and in your script just before your truffle line in your script, and compare the two. If there is a difference, then the problem is with the PATH in your shell script.

How to execute node.js script by using .bat file?

I want to execute this script pm2 start d:\nodejs\ecosystem.config.js using .bat file
(I'm on windows 10)
but when I execute .bat file, it didn't work
I can't find any clues on any web, google
node d:\nodejs\ecosystem.config.js
Above command should execute the javascript file if the node is installed in the PC.

How can I run a node app from the command line and return control?

I run a angular app like this:
npm run server-java
From a terminal window.
The server starts, but I want it to give back the shell prompt.
I want the shell prompt back while it runs.
You can use tools like pm2 or forever to start your nodejs app as a background process. Usually used for production setup.
Another option is:
npm run server-java > /dev/null 2>&1 &
You will get back to the terminal, but then you have to kill process manually by id when you don't need it.

Node.JS Command Prompt

I was messing around with the npm package today and I noticed that all of my commands were being run from my command prompt on my machine rather than through the node.js command line that comes with the download.
Bottom line: Why is there a node command prompt if you run commands from your local command prompt?
I saw there was a question like this here: node.js command line tool but it doesnt exactly answer the question.
I appreciate any help out there.
The node.js command prompt has your node.js environment set-up. Most of time, if you try to install some global package through your local command prompt, it will not work as expected, but if you use node.js command prompt it will. Happened to me while trying to use the express-generator.

Run command line app in visible console using NodeJS under Windows

I'm trying to write a command line tool using NodeJS on Windows.
The tool need to execute several other exe's and according to the exit code of each of them progress or stop.
I'm able to run the other exe's using child-process but mostly for debug purposes I'll like to run the other exe inside their own console window. The other exe is doing complex things inside the console window so simply printing out the stdout is not enough.
I've try both exec and spawn and also prefix my other exe with cmd and start but nothing did the trick.

Resources