Answer the question
In order to leave comments, you need to log in
How to run js file using task scheduler?
Good afternoon, tell me please
. I have a main.js file, I run it through the node main.js terminal,
but I can somehow launch the file after a certain period of time
(simulate my input in the node main.js terminal)
(wrap the contents of the file in the function and then the function to run after a set interval or the scheduler is not suitable)
I figured out how the task scheduler works, how to run functions using it, but I don’t know if it’s possible to run the file and I couldn’t google something on this topic
const scheduler = new ToadScheduler()
const task = new Task('simple task', () => .............тут main.js файл)
const job = new SimpleIntervalJob({ seconds: 120, }, task)
scheduler.addSimpleIntervalJob(job)
Answer the question
In order to leave comments, you need to log in
const scheduler = new ToadScheduler()
const SSH = require('child_proccess')
const task = new Task('simple task', () => {
try{ var msg = SSH.execSync('node main.js') } catch (err){ console.error(err.toString()) }
})
const job = new SimpleIntervalJob({ seconds: 120, }, task)
scheduler.addSimpleIntervalJob(job)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question