Node.js Command Prompt - node.js

I'm trying to learn Node.js. I really like a lot of the ideas I've seen. Currently, I have "Hello, World" working. To run hello world, I simply type node hello.js from a windows command prompt. Now, I'm trying to integrate Node in with Visual Studio as a Tool. Essentially, I want to be able to click the "TOOLS" menu in Visual Studio and choose "Node", and my currently selected file will run in a Node environment.
My question is, how do I do this? Currently, I have the following external tool configured:
Title: &Node
Command: C:\Windows\System32\cmd.exe
Arguments: node $(ItemFileName)
Initial Directory: $(ItemDir)
When I choose "Node" from the "TOOLS" menu, a command prompt window is opened. The directory is set to the directory of the file I've chosen. However, the command "node [filename]" doesn't get executed or entered. What am I doing wrong?

So I replicated the issue you've experienced so I've tried to simply point it to node.exe instead and seems to work pretty well ;)) Will probably end up using this as well!

Related

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 cmder from start menu

I have been vexed by what I felt should be an easy issue to solve. I have been trying to run the cmder executable from the start menu. But when I type the Cmder in the Run box, Cmder.exe does not show up in the list
But I can see from the cmd that Cmder.exe is present and when I run that exe in cmd , Cmder opens up.
Is there some reason that Cmder.exe does not appear in my start/run command?
Thanks in advance
The reason for this is that Cmder isn't installed like a typical Windows application.
The solution is to add Cmder to your computer's path. See Henrik Sommerfeld's blog post.
Additionally, if you're interested in learning more about what is being used for your searches, click the Filters button. See image below:
Instead of using the Start Menu, install Keypirinha. Then add the folder where you store Cmder and similar tools, to the Keypirinha and you can get rid of the Start Menu.
Keypirinha is faster and much more flexible than the Start Menu - e.g. let you pick the apps from somewhere on your machine.
I have a lot of XCopy-deployable tools like Cmder (and Keypirinha too) in an "Application" Git repository. If I have to provision a new developer machine with all the beloved developer tools, now the fast way is:
install Chocolatey
install Git Extensions via Chocolatey
clone my "Application" Git repository
This a done in less than 10 minutes and it covers 95% of my toolset.
To have CMDER on Windows Context Menu (right click) wherever you want.
Open a terminal as an Administrator
Navigate to the directory you have placed Cmder
Execute .\cmder.exe /REGISTER ALL
If you get a message "Access Denied" ensure you are executing the command in an Administrator prompt.
In a file explorer window right click in or on a directory to see "Cmder Here" in the context menu.
From: https://github.com/cmderdev/cmder#shortcut-to-open-cmder-in-a-chosen-folder
Tip: put the CMDER files in c:\Program Files\CMDER

How to hide node cmd windows created by "pm2 start"

One cmd window per node process, I don't know what these windows for. Can I hide them?
Using AutoHotkey I solved this problem for me on Windows. This will add a tray icon in the notification area of the taskbar (somewhere next to the clock). You can also stop the script itself and the node.js script by right clicking this icon then "Exit".
#SingleInstance, force
OnExit, ExitSub
RunWait, node "main.js", % A_ScriptDir, Hide, pid
ExitApp
ExitSub:
Process, close, % pid
ExitApp
With %comspec% you can write the output to a file if needed. This would then be something like RunWait, %comspec% /c "node "main.js" > "log.txt""
What you can do is, well... in my case I use Visual Studio Code, you forgot to include your IDE in your question. Now with VSC I have integraded the terminal, so I don't really have 3 windows floating around. Now, there is a work-around with windows, which in mac doesn't happen, in order to have the 3 windows you would have to include in your settings:
//Terminal Configurations
//PowerShell Windows
//"terminal.integrated.shell.windows": "C:\\WINDOWS\\system32\\cmd.exe",
//GIT Bash Configuration
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
so when you clik on the plus, it would create a "new window" but not floating around, look:
Btw, you cannot have both activated at the same time, one for bash, one for cmd, I use cmd for my mongodb, and bash for the rest.
You can also substitute bash or cmd for nodejs command line if you wanted to, just put it in one of the routes above :)
Hope it helps!

Node.js explain Errors in REPL?

I tried this
.save myShell.js
that is followed by this error:
Failed to save:myShell.js
why do I get this error ?
I save the situation with the start of the node.js command promt.
By windows install you get (so was after install on my sys) some several shortcuts , one with the node.js icon and it's name ist Node.js and another that is called Node.js command promt - if you want to use the .save command to save the session you must to run the "Node.js command prompt".
Of course with some more work you can get more.
Permissions issue.
2 options:
Run "Node.js" app as administrator (right click on the icon in the start menu "run as admin"
Run "Node.js Command Prompt" app and then type "node" which will put you in REPL

running a server file on node.js

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)

Resources