PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How to make automated notifcation Sender using Nodejs

 July 13, 2022     node.js, web-deployment     No comments   

Issue

I wanted to make a function which will send the list of users a notification (Email) and want this to continue after every 6 hrs regularly. Something like this

function(){
   if(currentTime==scheduledTime){
      //Triger notification sender
      sendNotification();
      scheduledTime = (scheduledTime + 6 hrs);
   }
}

How can I implement this Feature. Also, where can I deploy this website with this kind of functionality for free.


Solution

You can use node-cron instead.You can setup the interval using cron syntax and it will run in a scheduled manner.

npm install --save node-cron

Then :

var cron = require('node-cron');

cron.schedule('* */6 * * *', () => {
  console.log('running a task every 6 hours');
  sendNotification();
});


Answered By - lousybear
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing