Answer the question
In order to leave comments, you need to log in
How to run multiple scripts in NodeJS?
Hello. It is necessary to launch the NodeJS server, which will simultaneously process API requests from the client, and in parallel, it is necessary to run a script that will run 1 time per second and make entries in the database. Is it possible to implement something like this?
Answer the question
In order to leave comments, you need to log in
Well, try to organize everything in the form of modules
//module2.js
function module2() {
console.log('module2 started);
setTimeout(function () {
setInterval(function () {
console.log(('module2 timer:' + new Date().getTime()));
}, 2000);
}, 1000);
}
module.exports = module2;
//index.js
const module1 = require('./module1'),
module2 = require('./module2');
module1();
module2();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question