{"id":8560,"date":"2026-02-16T05:47:29","date_gmt":"2026-02-16T05:47:29","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=8560"},"modified":"2026-02-16T05:49:58","modified_gmt":"2026-02-16T05:49:58","slug":"scheduling-jobs-in-node-js-with-node-cron","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/","title":{"rendered":"Scheduling Jobs in Node.js with node-cron"},"content":{"rendered":"<p>In many applications, you might need to run certain tasks automatically at specific times. For example, sending daily emails, cleaning up a database, or generating reports. In <a href=\"https:\/\/blog.webnersolutions.com\/using-worker-threads-in-node-js\/\">Node.js<\/a>, one of the easiest ways to schedule these tasks is by using the node-cron package.<\/p>\n<p>In this blog post, we will learn what node-cron is, how it works, and see a simple example.<\/p>\n<p><strong>What is node-cron?<\/strong><br \/>\nnode-cron is a Node.js library that allows you to schedule tasks (also called \u201c<a href=\"https:\/\/studysection.com\/blog\/data-synchronization-with-rsync\/\">cron jobs<\/a>\u201d) to run at specific times or intervals. It uses a cron syntax, which is a common format for defining time-based schedules.<\/p>\n<p>A cron job uses 5 fields to specify its schedule.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-8561\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2026\/02\/Untitled-drawing-11-300x114.png\" alt=\"\" width=\"300\" height=\"114\" srcset=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2026\/02\/Untitled-drawing-11-300x114.png 300w, https:\/\/studysection.com\/blog\/wp-content\/uploads\/2026\/02\/Untitled-drawing-11.png 677w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Installing node-cron<\/strong><br \/>\nTo use node-cron, you first need to install it in your Node.js project:<br \/>\nnpm install node-cron<\/p>\n<p><strong>Basic Example<\/strong><br \/>\nHere\u2019s a simple example to run a task every minute:<\/p>\n<pre><code>const cron = require('node-cron');\r\n \r\n \/\/ Schedule a task to run every minute\r\n cron.schedule('* * * * *', () =&gt; {\r\n     console.log('This message runs every minute:', new Date());\r\n });<\/code><\/pre>\n<p><strong>Explanation:<\/strong><\/p>\n<ul>\n<li>&#8216;* * * * *&#8217; \u2013 This means the task will run every minute.<\/li>\n<li>The callback function contains the code that will execute according to the schedule.<\/li>\n<\/ul>\n<p><strong>More Scheduling Examples<\/strong><\/p>\n<p>1. Run every day at 8:00 AM<\/p>\n<pre><code>cron.schedule('0 8 * * *', () =&gt; {\r\n     console.log('Good morning! Time to start your day!');\r\n });<\/code><\/pre>\n<p>2. Run every Monday at 9:30 AM<\/p>\n<pre><code>cron.schedule('30 9 * * 1', () =&gt; {\r\n     console.log('Weekly meeting reminder!');\r\n });<\/code><\/pre>\n<p>3. Run every 10 seconds (for testing purposes)<\/p>\n<pre><code>cron.schedule('*\/10 * * * * *', () =&gt; {\r\n     console.log('This runs every 10 seconds');\r\n });<\/code><\/pre>\n<p><strong>Note:<\/strong> It supports seconds if you use 6 fields instead of 5.<\/p>\n<p><strong>Stopping a Cron Job<\/strong><br \/>\nYou can also stop a scheduled task using the stop() method:<\/p>\n<pre><code>const task = cron.schedule('* * * * *', () =&gt; {\r\n     console.log('This will run every minute');\r\n });\r\n \r\n \/\/ Stop the task after 5 minutes\r\n setTimeout(() =&gt; {\r\n     task.stop();\r\n     console.log('Task stopped');\r\n }, 300000); \/\/ 300000ms = 5 minutes<\/code><\/pre>\n<p><strong>Use Cases of node-cron<\/strong><\/p>\n<ul>\n<li>Sending daily, weekly, or monthly email reports.<\/li>\n<li>Cleaning up old files or database records automatically.<\/li>\n<li>Scheduling reminders or notifications.<\/li>\n<li>Fetching data from APIs periodically.<\/li>\n<\/ul>\n<p><strong>Summary<\/strong><br \/>\nScheduling tasks in Node.js is simple with node-cron. By understanding the cron syntax and using its API, you can automate almost any repetitive task in your application. Start small with simple schedules and gradually move to more complex tasks as needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In many applications, you might need to run certain tasks automatically at specific times. For example, sending daily emails, cleaning<\/p>\n","protected":false},"author":1,"featured_media":8562,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scheduling Jobs in Node.js with node-cron.<\/title>\n<meta name=\"description\" content=\"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scheduling Jobs in Node.js with node-cron.\" \/>\n<meta property=\"og:description\" content=\"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-16T05:47:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-16T05:49:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2026\/02\/Scheduling-Jobs-in-Node.js-with-node-cron.png\" \/>\n\t<meta property=\"og:image:width\" content=\"940\" \/>\n\t<meta property=\"og:image:height\" content=\"788\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Scheduling Jobs in Node.js with node-cron\",\"datePublished\":\"2026-02-16T05:47:29+00:00\",\"dateModified\":\"2026-02-16T05:49:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\"},\"wordCount\":289,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\",\"url\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\",\"name\":\"Scheduling Jobs in Node.js with node-cron.\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2026-02-16T05:47:29+00:00\",\"dateModified\":\"2026-02-16T05:49:58+00:00\",\"description\":\"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scheduling Jobs in Node.js with node-cron\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scheduling Jobs in Node.js with node-cron.","description":"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/","og_locale":"en_US","og_type":"article","og_title":"Scheduling Jobs in Node.js with node-cron.","og_description":"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.","og_url":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2026-02-16T05:47:29+00:00","article_modified_time":"2026-02-16T05:49:58+00:00","og_image":[{"width":940,"height":788,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2026\/02\/Scheduling-Jobs-in-Node.js-with-node-cron.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Scheduling Jobs in Node.js with node-cron","datePublished":"2026-02-16T05:47:29+00:00","dateModified":"2026-02-16T05:49:58+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/"},"wordCount":289,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/","url":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/","name":"Scheduling Jobs in Node.js with node-cron.","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2026-02-16T05:47:29+00:00","dateModified":"2026-02-16T05:49:58+00:00","description":"node-cron is a Node.js library that allows you to schedule tasks (also called \u201ccron jobs\u201d) to run at specific times or intervals.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/scheduling-jobs-in-node-js-with-node-cron\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Scheduling Jobs in Node.js with node-cron"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":27,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/8560"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=8560"}],"version-history":[{"count":2,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/8560\/revisions"}],"predecessor-version":[{"id":8564,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/8560\/revisions\/8564"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/8562"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=8560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=8560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=8560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}