Is this the right way to create a Cron Job in Node env, using Render.com

I created a Cron job (to be called every minute, just for testing) using node env. It was called only once, the first time it started and was never called again.
Please advice if I have implemented correctly ?

Here is my render.com settings .
command: npm start

build command: npm install
Schedule (every minute): * * * * *

Logs from render.com

Mar 3 03:32:06 PM  Example app listening on port 3000
Mar 3 03:33:29 PM  ==> Starting service with 'npm start'
Mar 3 03:33:29 PM  
Mar 3 03:33:29 PM  > myapp@1.0.0 start /opt/render/project/src
Mar 3 03:33:29 PM  > node app.js
Mar 3 03:33:29 PM  
Mar 3 03:33:30 PM  Server running

Here is my package.json

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "node-cron": "^3.0.2"
  }
}

Hi,

It looks like you’re trying to run an Express server as a Cron Job

 Example app listening on port 3000

A Cron Job should just be a script that will do some work, then exit, not continually run like an Express server.

If you want to use Express, you probably want a Web Service.

Also, depending on what your Cron Job is looking to do, 1-minute intervals could be a little ambitious. The service would need to spin-up, run the job, exit and spin-down in that time, to be ready for the next minute. If you need something almost continually running like this, you may find a Background Worker with a scheduler more suitable, e.g. repeatable jobs in Bull.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.