N
N
ndsdmfwg2016-09-23 10:24:43
Node.js
ndsdmfwg, 2016-09-23 10:24:43

The task is to monitor one resource, how to organize it?

It is necessary to check the data of one resource, and immediately notify about updates. I use the request module, but what should I use, say, to do a check every 5 minutes, a daemon on a node, or something else? It seems that if I write something on the node, then in an hour the memory will fill up and the process will simply die, what should I do? Is there any correct way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
ndsdmfwg, 2016-09-23
@ndsdmfwg

Three years have passed since the last reply. Node.js has matured significantly during this time, so the question has not lost its relevance.
I think it's worth mentioning a few more options that are missing in other answers.
Forever
The forever package exists in the Node.js ecosystem. It can be used as a spawn daemon for your application. Of the advantages of this solution, one can note the simplicity and the ability not to write additional code. In addition, forever can be configured to automatically restart the application when it crashes. Of the minuses, the need to drag a daemon script into the node.js system that needs to be installed globally. In some cases this may not be acceptable. Running the application using this solution looks like this:
forever start app.js
and stop it:
forever stop app.js
PM2
Another popular solution from the Node.js ecosystem is the PM2 process manager. As with forever, pm2 is a globally installed node.js daemon process (with all the pros and cons). After installing it, the application is started by the command:
pm2 start app.js
and it is stopped:
pm2 stop app.js
init.d
You can write a regular init.d script for your application. This path is used by all normal Linux services. If we talk about the advantages of this solution, then your application will be started and stopped by the system itself, there is no need to install an extra daemon process. Of the minuses - you have to restart the application when it falls manually (or using special utilities). You will also have to write the init.d script itself. As a basis, you can take, for example, this solution. Launching an application using this solution looks like this
service app-service-name start
and stopping it
service app-service-name stop
----------------
an article on Habré about this
https:/ /habrahabr.ru/sandbox/96765/(Demonization of NodeJS applications using PM2, 2015)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question