Run a node.js server from Geany - node.js

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

Related

How do I make a clickable terminal link that runs a function in node.js?

I am using ansi-escapes to make the link.
How would I make it run a function when the link is clicked? I'm okay with making it run a terminal command. And if so is there some sort of URI that I can use to run a terminal command? I am using Windows Terminal, however I would like it to work for other terminals as well.
If you make a link with a file:/// uri to a batch file, Windows Terminal will run it, because it simply executes open ${url}. From that batch file you can then run something like node terminalCallback.js.
The only allowed uri protocols are:
http(s)
file

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

Any good text editor for which I can write plugin/extensions in nodejs?

Is there any good text editor available for which I can write plugins/extensions using nodejs? I have a node app which I run like this
node app.js -c fileName.js destFile.js
so I want whatever file I am editing, I can select some menu and the node command runs with fileName as current file.
look into Githubs Atom editor. It's a very customizable text editor that uses node.js and other web technologies.
Please try geany.
You can set build command :
- add Execute for examples, add in command : node
And in terminal below, You can stop node with control c

setting environment variables for node.js child process

I have a node webkit app, part of which involves using child processes in node to call pdftk (a separate command line program).
I don't want my users to have to install pdftk or use the command line, so I included pdftk in the packaged version of the node webkit app. If I run this packaged app from the command line, it works fine - and I assume that's because it's using the version of pdftk that's installed on my computer, not the one packaged with the app.
When I try to launch the app by double clicking on an icon in the gui, as I'd want a user to be able to do, I get a node.js error - child process ENOENT. I think that's because when launched through the gui, it doesn't inherit the environment variables (including PATH) from my command-line environment.
I know I can set environment variables as an option when I call the child process, but haven't been able to figure out how to do that correctly. I'm not sure what variable I should set, or what I should set it to. I suppose I'm not sure if it's even possible to call pdftk from within the packaged app, or if I would need to have the user install it on their own computer. Any help would be much appreciated.
I think this might not be about environment variables. I guess when you run from the command line your current working directory (CWD) is where the app is. And I think you set the path to pdftk relative to the node script. When you double click (a shortcut) the current working directory and the path where the node script is located are different so relative paths don't work as expected.
When you use relative paths, always use __dirname to get the path the node script is on and use it to set path to the pdftk file. The path.resolve function can be useful when doing this. Read path.resolve documentation
I strongly recommend you to check this question and answers
How do I get the path to the current script with Node.js?
What is the difference between __dirname and ./ in node.js?

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