Tuesday, 29 May 2018

Dynamically modify an "extra" js file and make functions exportable without a restart?

How to write to a js file and immediately make a method exportable without restarting server?Im trying to make a user input CRON mechanism. So user can input on frontend whatever CRON schedule they want to complete task.In node what Im doing is1) writing the CRON task to a local file (so I have a permanent record of it in case of server issue) 2) writing using node-cronso my cronTaks.js file looks a little likeconst task_123abc = cron.schedule('*/10 * * * * *', () => { console.log('hey Robbie'); }, false); Im having difficulty being able to use node-crons methods .start(), .stop(), .destroy().My first attempt was to simply add task_123abc.start() on my cron job .js file and "requiring it". Only when I try to edit the file and replace .start with .stop() and re-require, my cron job continues.How can I start off with an empty js file, append to it a method (in this case a cron), immediately make that new method exported so the main function can call .start() or .stop() on it?Any tips/advice/suggestions?

Submitted May 29, 2018 at 05:22PM by itsmoirob

No comments:

Post a Comment