Run command line app in visible console using NodeJS under Windows - node.js

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.

Related

Is there a way to get printouts from an pyqt5 application built with fbs for Windows without being a debug build?

Use case: Would like to add CLI functionality to a application built with fbs.
When building for Ubuntu it prints out everything when I run this application from the command line, which is what I want. Building with the same settings but for Windows instead I'm not getting any printouts when I try to run this from Powershell or Command Prompt. On Windows the application also seems to be put into the background making it less obvious when it is finished. When application hits an unhandled exception it does not print the error into the command line but into its own window.
Is there a setting you can use to allow printouts for Windows? I know you have a debug build setting which does this but releasing a release as a debug build does not seem right.
cmd /c <name-of-app>.exe This resolves the issue not knowing when the application is done, it does not print out any messages however. It also prints out any unhandled exceptions into its own window.

How to use Command Prompt after ng serve was compiled

In Angular 5, after creating project folder, installing Angular CLI, Node.js (all latest versions) and ng serve was compiled successfully through command prompt. Then I tried to use command prompt to install bootstrap. I could not control / use command prompt. What might be the cause and effect?
Command prompt stuck after compilation
There are simple ways:
If you use Command Prompt(Terminal), open another Command Prompt inside your project path.
If you use IDE like Visual Studio Code, open Terminal and then you can use Plus(+) sign for openning anothor Terminal like below image:
If you use IDE like WebStrom (Jetbrains IDE), first open IDE Terminal then make right click and select New Session and new terminal openning like below image:
There are couple of ways you can do that.
The official way of deployment of angular app.
Create a start.bat (if you are using windows) and write the ng serve --open command there. Now you can run this file which will internally run your angular app, using forever or pm2 npm modules.
If you do that these will demonise your process to run in background and your same command prompt becomes usable again.
Once the process is finished( compiled successfully), you would notice that the cmd -prompt newline doesn't show any directory and its blank.
This means that, you just have to open an another (new terminal), get to the right directory using "cd command "and implement your desired commands or operations again.
use ctrl + v it will ask weather to terminate say Y, cursor will go back

How to run a node.js file as a background process on a Windows server?

I was creating a node.js project and uploaded it to my Windows server to provide an API service for mobile application.
When I open command prompt and type
node app.js
It runs correctly, but when I close the command prompt my node.js server stopped running.
How to make it still running when I close the commend prompt?
For example on Ubuntu I use the command
nohup
How can I do this on Windows?
You can make the process run in background using pm2
pm2 start app.js --watch
This will start the process and will also look for changes in the file.
More about watch flag
Nodemon #ftw. On Windows, Forever doesn't really watch files so much as casually observe them, while pm2 restarts the server every time you load a page.
Each of these tools works similarly, and each installs just as in the accepted answer. E.g.:
npm install nodemon -g
This installs nodemon globally, and to use you can simply navigate to your project folder and enter:
nodemon
(Assuming your project has an app.js file). You can add the -w switch, just as in Forever and pm2, however if you're just wanting to watch all files, you can omit that. To run nodemon in the background with Forever, you would run this:
forever nodemon --exitcrash
Nodemon is good for development, especially on Windows, while Forever and pm2 are more for production, on Linux.
Here is a simpler answer that cuts right to the chase without any added libraries or overhead like in the other two answers described above. To run your Node.js application as a windowless startup program in the background (this would be analogous to "nohup" in Linux), modify this template to suit and copy it into a .VBS script file. Then copy that file to your Start Menu startup folder (for all users, that would be C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup) and it will automatically run. The techniques you are using here in Visual Basic are (1) preparing to run the Node.js application by first changing the working directory of the shell object and (2) informing the shell to run the Node.js application in a hidden window by adding a “, 0” immediately after the run function:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = "C:\path-to-your-node-js-app\"
objShell.Run("""node"" your-app.js"), 0
Set objShell = Nothing
References:
https://keestalkstech.com/2016/07/start-nodejs-app-windowless-windows/
https://devblogs.microsoft.com/scripting/how-can-i-change-the-working-folder-of-a-script/
No, you can't.
Even if you make a GUI program you'll need to run it via console.
And as soon as you close the command prompt. Your service would be stopped/ terminated that moment only. Because node creates a server itself while running : http.createServer().listen(port) or app.listen(port). So this this makes it independent in nature.
So, as soon as you close the command prompt on which server was running all the services would stop at that moment.

Node.js open in a new console without pause

I'm very newby in node.js world, and I'm doing the first steps, but I can't step forward because when I try to do any operation from node.js command prompt in Windows 10, the node.js console is opened and closed very fast and I haven't time enough to read the errors or anything that is written on console. Is there any way to configure node.js to stop the console before to quit it? Or to execute on same opened Node.js command prompt.
For example I'm unable to read the version of different modules installed, the console opens and closes very fast.
I've tried windows standard command line, node.js command prompt, an application called cmder, and in all instructions related to node it throws a new window with node.exe. If the command waits user prompt the console (node.exe) is paused, but when I try an application that only log some data (like npm --version) I can't see the result, because after log, the console is closed.
Some time ago, I've tried in Windows 7, and I remember that the node prompt was opened on the same command console. I don't know if it's the SO, or the node.js version (4.4.4 LTS).
Ouch! I've found the solution, I was trying to avoid the annoying "run as administrator" dialog and I've configured the node application properties checking the flag "Compatibility > Run This Program As An Administrator". That was the source of all my problems!
Hope it helps anyone!

Run a node.js server from Geany

A simple question: Is it possible to configure the Geany IDE so that Node.js servers can be run directly from Geany using the "Run" button?
When inside a JS file, go to Build > Set Build Commands, there should be a section title Execute commands. To use node to execute your files, put: node "%f" in the "Execute" command textbox.
When you change this, any .js files you are editing will run node in the virtual terminal when you hit F5.
If you want to set up an entire project to run the server whenever you're working somewhere within a given directory structure, you'll have to mess with project-level configuration. (something I don't usually bother with) My solution here just gives you a quick way to execute a single JS file without using an external terminal.
UPDATE: node "%f" seems to be legacy, but nodejs "%f" works

Resources