Way to connect Clojurescript Repl to running node process - node.js

I was wondering if there is a way to connect a cljs repl to a nodejs process that I already have running, that is say in debug mode and stopped at a breakpoint.
So I know there is https://github.com/bodil/cljs-noderepl, and I have this running fine, but it starts up a 'sandboxed environment' as it says in the documentation. I'd like it to connect to a node process of my choosing (e.g. node debug my_project.js).
I can use the normal node debugger, but that's plain old JS, not CLJS.
I also looked into nRepl, but that doesn't seem to be the solution.
Is what I'm asking for possible at the moment, or can I only do this type of repl in a browser environment?
Thanks

I know it's a bit late, but I don't think node has a way to communicate with a running enviroment. nREPL actually is a step there as it will listen in a nodejs app and let clients send it code, but I haven't seen a nREPL server for node.js clojurescript.
The best I've gotten is https://plus.google.com/112151928607622120183/posts/fNr5h8BgLEp

Related

How can I connect to a running node program with my repl

I am using Bodil Stokkes node repl https://github.com/bodil/cljs-noderepl. Starting it is very easy. Just as described in the docs.
Now I'd like to connect my running node program to the repl. However I can't figure out how to do that. Can anybody give me a step by step instruction.
What I want to do is
node out/main.js => starts my node process
lein trampoline noderepl => this should somehow connect to the process in main.js
Optionally I'd be happy if I could start/access my main program from within the node-repl.
Check out Vantage.js. It let's you connect into live Node apps on the fly. This looks like what you're trying to do.
Disclaimer: I made it.

Compute Engine and NodeJS, keep online

I have a website already developed with node.js and sails.js on "Compute Engine" but to start it, necessarily I have to write "node app.js" in the SSH console of browser. But there is a problem (since I am new to Linux and Google Cloud :)), if I want my Node app it keep online, the SSH window must be open, if I close, the Node application will terminate, like Ctrl+c. So it makes no sense to have my computer turned on, just to have the active window. So, how to keep my NodeJS app online without being in the presence of SSH console?. I know the question is illogic to some, but I would appreciate if you help me. Thanks
First of all it is not related to Compute Engine nor Node.js.
You mention that the application will terminate if you press ctrl+c and that's correct because you are running your application in the foreground instead of background. To run your application in the background you can either launch your app like this:
node app.js &
Or you can launch with node app.js and then press ctrl+z.
But just sending the application to the background wouldn't help. As soon as you disconnect from your ssh session, all programs started (background or foreground) will receive a HUP signal, in node.js you can handle that signal but the default behaviour is to close:
On non-Windows platforms, the default behaviour of SIGHUP is to terminate node
One thing that you can do to ignore the SIGHUP signal is running your app as follows:
nohup node app.js &
If you do this, your application will continue to run even when you close your ssh session. Another way to achieve this is by using the screen.
This will help you on very early stage and for development but I don't recommend using neither of these things for production. Eg: if your application crash it should be restarted. The recommended way is to use a service manager that comes with the OS: upstart, systemd, init, to name a few.
You can install forever module (https://www.npmjs.com/package/forever) to your Google compute engine using SSH window.
npm install forever -g
Then, in your node server directory, execute your server using forever.
forever start [YOUR_SERVER_FILE.js]
Now, if you close the SSH window, your node server is still on !!
Good luck!
The best solution would be using a module called forever:
https://www.npmjs.com/package/forever
You can use it this way:
forever start your_script.js

How are most Node applications started?

I know to start my Node app I type in the Win shell, node app.js.
But this is obviously not how a webhost would maintain a Node webserver (ie what happens if there is a power outage, a Node exception, etc).
I see things like Forever and running Node as a Windows service, but I feel like the creator of Node must have had a different idea? Something like Apache is installed as a Windows Service so that it runs even if the server reboots - what is the correct method of doing this for Node? I don't like the idea of introducing another piece of software just to keep the server going.
Thanks.
The problem is that many systems do not do that. For instance MongoDB doesn't even run like that on windows.
The best solution I have found is this https://nssm.cc/
Also you have to consider even on Linux you need to run something like upstart to keep node programs running when you close the console.

Does Koa need Forever?

Koa has implemented not having a web server shut down when one page has an error. My question.... is this error handling behaviour robust enough that one no longer needs to use Forever when hosting a node site?
You should still use forever (or nodemon, a bit easier to use in some cases) to keep your server running. There are other things that can cause it to crash in a production environment, not just bad requests.
In development, I've seen insane uptime on some koa apps without using forever/nodemon, but I would not do this in production. It's asking for a 3 am phone call :)
If you're using Linux/Unix, you should also consider using tmux to keep it running in a separate terminal session, or it can timeout with your terminal session. (Type tmux new -s koa to get started). Here's an article on using tmux with upstart: https://bowerstudios.com/node/953

node.js app running using forever inaccessible after a while

I have a node.js server and a java client communicating using socket.io. I use this api https://github.com/Gottox/socket.io-java-client for the java client. I am using forever module
to run my server.
Everything works well but after some time , my server becomes inaccessible and I need to restart it, Also, most of the times i need to update/edit my node.js server file in order to make my server work again (restarted). Its been two weeks already and im still keep restarting my server :(.
Has anyone run into the same problem ? and solution or advice please.
Thanks

Resources