# How to set up a cron job that runs a Node.js app

> Learn how to set up a cron job that runs a Node.js app by writing a run.sh script, making it executable with chmod, and scheduling it through crontab -e.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2022-05-03 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/cron-job-nodejs-app/

Create a shell script in a file, for example called `run.sh`

```sh
#!/bin/sh
node app.js
```

Give it execution rights

```sh
chmod +x run.sh
```

Then 

```bash
crontab -e
```

By default this opens with the default editor, which is usually [`vim`](https://flaviocopes.com/linux-command-vim/).

| Tip if you're new to vim: use `i` to enter insertion mode, so you can type/paste, then `esc` and `wq` to save and quit.

Now you can add one line for each cron job.

The syntax to define cron jobs is kind of scary. This is why I usually use a website to help me generate it without errors: <https://crontab-generator.org/>

I also built my own free [cron builder](https://flaviocopes.com/tools/cron-builder/) that translates the expression to plain English and shows the next runs.

![Crontab Generator website interface showing form fields for scheduling cron jobs with time intervals and commands](https://flaviocopes.com/images/cron-job-nodejs-app/Screen_Shot_2020-09-09_at_18.03.57.png)

You pick a time interval for the cron job, and you type the command to execute.

I chose to run this every every day at 10AM. 

This is the crontab line I need to run:

```
0 10 * * * /Users/flaviocopes/dev/run.sh >/dev/null 2>&1
```

If all goes well, the cron job is set up.

Once this is done, you can see the list of active cron jobs by running:

```bash
crontab -l
```

![Terminal output showing crontab -l command result with an active daily 10 AM cron job scheduled](https://flaviocopes.com/images/cron-job-nodejs-app/Screen_Shot_2022-04-23_at_20.11.46.png)

You can remove a cron job running `crontab -e` again, removing the line and exiting the editor.
