Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run service in Express.js regardless of recieved requests

I have a backend application made in nodeJS and express. The main app is divided into separate file, app.js and index.js. app.js is used for managing express, adding its controllers and connecting to MongoDB. index.js is there just for creating server.

Now I would like to implement service, that will check the current state in database, and in case of true, run some code, or function. And that code should be running all the time, regardless of sent requests. It should be a code for itself. So if anyone could tell me what is the best way of implementing this kind of behaviour.

Thank you!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There can be multiple ways. I am sharing two of them.

  1. Using Scheduling methods of JS which allows you to run some code in a time interval.
  2. Using a Job Manager or scheduler. This article will help you to understand how to build a queue-based job manager using redis.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading