S
S
shedy22015-04-24 20:14:04
linux
shedy2, 2015-04-24 20:14:04

How to work with a running Node.js application through the command line?

I have a website application that works with many clients in real time.
And this application is running as a daemon. I would like to be able to manage this application from the console (but at the same time not make a cli application .. let it constantly hang in the background and not close when I exit the console).
For example, take and send the same message to all users.. Or display a list of active ip-addresses, or something else. There are a lot of custom tasks for which I do not need a web interface at all. With Linux at the beginner level, it seems that you can somehow use signals or something like that, but there, in my opinion, you can’t pass the argument
How to organize it correctly? Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timur Shemsedinov, 2015-04-25
@MarcusAurelius

You need to make two applications, one is a service, the second is a CLI, and transfer information between them via one of the following methods: HTTP (the simplest and most convenient, but you need to implement the protection of control URLs either by a secret key or by IP or through authentication), through the message bus (from Redis, ZMQ, RabbitMQ, etc.), through configuration files (CLI writes to files, and the service monitors changes through fs.watch), through IPC, and there are a lot of other ways.
There is a second way , you can also make a built-in telnet server or ssh server at the HTTP server of your node and connect to it with the console, as I like it. Here is a person doing something similar: www.davidmclifton.com/2011/07/22/simple-telnet-ser... There are even libraries already here: https://www.npmjs.com/package/sshor here: https://github.com/mscdex/ssh2

S
StrangeAttractor, 2015-04-24
@StrangeAttractor

You take and implement the desired functionality in the format of a web service, then curl via HTTP...

K
Konstantin Kitmanov, 2015-04-24
@k12th

Is it critical for you to connect to an existing application instance for any reason, do you have something stored directly in memory? Otherwise, you can always call node in the application folder and import the necessary modules directly into the REPL, connect to the database and do everything you need. If something needs to be done many times, you can save it to a script.
PS Your prayers were heard, today they wrote about vantage on dailyjs - exactly what you wanted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question