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!
Related
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.
What can I do to make node/npm/related commands send their output back to the terminal I used to launch them?
I've recently installed NodeJS 10.4.2 on Windows 10. When I run any node or npm command from PowerShell, Git Bash, or the Node terminal shortcut, a new window is opened, the output is directed there, and the window is closed. I feel like there must be a setting I've flipped under a previous installation, but I can't find it, and it's making me bananas.
I don't believe this behavior is correct at all, but please correct me if I'm mistaken. So I have an Angular 2/Ionic 2 app created all through the Node.js command prompt... the commands all work fine, up until I execute ng serve, after that I can't type at all into the command prompt. Only way I can type is if I close out of the command prompt and restart (less than ideal). Is this normal behavior? Or only occurring on my machine?
ng serve launches a basic web server for you using which your static files are served. It also listens for updates to your project files and if any changes are detected it bundles the project again and reloads the browser tab automatically. So it's important that it keeps running when you're developing your application.
I installed the .msi file from nodejs website and installed it.
Now, when I run nodejs.exe, I do get a command prompt, but it shows a blinking > by default, instead of C:/>
It looks somewhat like this:
What to do?
This is called the REPL. You can enter statements for Node to execute and get realtime feedback. Ctrl+C twice will get you back to the command prompt.
I recommend checking out the answers to How do I get started with Node.js for learning more about Node.js and how it works. Typically you provide a file with your Javascript for Node to execute:
node app.js
or you can leave the .js off:
node app
I've been practicing with "hello world" examples of websockets and node.js server.
According to all those examples you create a html file (client) and a js file (server).
Before you run them, you have to run this on the command line (I use windows)
node nameOFtheServer.js
So, my question. If I close the command line window and open it again the client does not connect to the server. I have to run again the above code in the command line , manually, so the server will start again. Why is this happening? Is that normal? How can I fix it , so I dont have to run the same commands over and over again on the command line in order to start the js file (server) ?
Thanks
EDIT
OK, new facts, I just edited the question, highlighting the changes in Italics
When you close the terminal, everything that runs in it is killed. There are many solutions on both Linux and Windows systems, most of them create some sort of a service which then runs in the background.
Here are some possible solutions:
http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever
https://github.com/indexzero/daemon.node
http://www.coretechnologies.com/products/AlwaysUp/Apps/RunNodeJSAsAService.html
http://coreybutler.github.io/node-windows/manual/#!/api/nodewindows.Service
Pick the one that is best for you.
Related question on StackOverflow:
How to run node.js app forever when console is closed?
First of all thanks Venemo for your anser. I tried use the forever module, but did not worked well, as you can see here.
So I decided to use nssm with node.js
I download the nssm and unzip it in the C:Program Files\path\to\nodejs. And then I opened Window's command window and typed C:\program files\path\to\nssm-2.16\win32 and then typed nssm.exe. You should see a "menu" how to install or remove services. And now type
"C:\Program Files\path\to\nssm.exe" install give-Your-Service-A-Name "C:\path\to\node.exe" \"C:Program Files\nodejs\path\to\yourServerFile.js"
Notice the \ before the "C:Program Files\nodejs\path\to\yourServerFile.js" it's not a typo, you should type it, is important, if you have spaces in your path, helps nssm to interpret correctly.
And that's it, now press CTRL+ALT+DEL, open the Services tab, and find give-Your-Service-A-Name , right click and select Start service. To check, open your client file that communicates with the yourServerFile.js, it should be working, without having to start the yourServerFile.js from command line.
(PS : I use nodejs 0.10.12 and nssm 2.16 on windows 7. The instructions above are a combination of this tutorial and this anser)