Member-only story

How to run a Cron job using NextJs/Vercel Framework

Bhavya Dhiman
3 min readOct 22, 2022

--

If you are not subscribed to medium membership, you can visit link here:

https://medium.com/@bhavyadhiman7/how-to-run-a-cron-job-using-nextjs-framework-b88d0e696aa2?sk=c97d4f3685fded6914743c0a59b438b6

Nextjs is a React framework to build static web pages and also for serverless developement. NextJs has file based router mechanism for which we will use the route using the external cron service. The API created through NextJs will be used by a external cron service.

I will show you an simple example:

To create a boilerplate for sample nextjs project, run the following command:

npx create-next-app

let’s name it sample-cron-app. After creating a project, navigate to the project directory and run npm run dev and hit the url: http://localhost:3000/api/hello

you will see the event log in the console as shown below:

Now, lets create a file named app.js and install cron package by using npm i cron and http request package (I used node-). The code is shown below:

const { CronJob } =…

--

--

Responses (1)