---
title: "Cron Jobs on Railway"
description: "A brief guide on deploying and running cron jobs on Railway using JavaScript."
date: 2022-08-18T00:00:00.000Z
updated: 2026-10-29T11:13:08.940Z
topics: ["Guides"]
tags: []
url: https://railway.com/guides/cron-jobs
---

# Cron Jobs on Railway

### **Update (31/08/23) — Cron Jobs now available on Railway**

Railway now supports Cron Jobs natively. It may be a better fit for you than what’s written here. Check out [https://docs.railway.com/cron-jobs](https://docs.railway.com/cron-jobs) for details!

---

Recently, we’ve had a few users ask us how they can go about deploying their cron jobs on Railway. While we don’t have first-party support for cron jobs, it is very easy to deploy them using language-level libraries.

This should be possible with all the languages we support. In this post, we will take JavaScript as an example and use the [node-cron](https://github.com/node-cron/node-cron) library to deploy a simple cron service on Railway.

---

## Scaffolding our cron service

At Railway, we treat a cron job just as we would anything else you deploy on our platform. Whether it is a web application, an API, or a cron job, for us, they’re all just services within a project.

So let’s go ahead and scaffold a brand new TypeScript package using [DTS](https://weiran-zsd.github.io/dts-cli/).

```bash
npx dts-cli create cron-service
```

Once the setup is complete, we can `cd` into `cron-service` and add the `node-cron` package.

```bash
yarn add node-cron
yarn add -D @types/node-cron
```

## Adding a cron job

Next, we can replace the existing code in `src/index.ts` with a basic cron job.

```tsx
import cron from 'node-cron';

cron.schedule(`*/1 * * * *`, async () => {
  console.log('running your task...');
});
```

The code above will simply log `running your task...` after every single minute as that’s what we have set the cron schedule as.

Before we run this, we will make one minor change to the `scripts` inside our `package.json` file which will help us when we deploy our service on Railway.

```json
{
  ...
	"scripts": {
    ...
    "start": "node dist/index.js"
	}
}
```

In the snippet above, we update the start script to use the built code from our `dist` directory. This will ensure the correct command is run when we deploy our service on Railway.

## Running our cron job

To run our cron job, we simply build and run our code.

```bash
yarn build
yarn start
```

![Demoing the cron service](https://cms.railway.com/media/e4160301dad804e5163f3bab3c64860494675c52545c5cd2c1275812ea8a4e94.png)

As you can see in the demo above, our message is logged to the console once every minute. In the next section, we will deploy this service to Railway.

## Deploying to Railway

We can deploy our new cron service to Railway by either adding it to an existing project or creating a new project. In this example, I will use the [Railway CLI](https://docs.railway.com/cli) to create a new project and deploy the service to that project.

![Creating a new project on Railway](https://cms.railway.com/media/61181d284b17a5ea0681c4c269619a7db1fac8b28c05b70f4216f19a6210d641.png)

Once our project is created, we can simply run `railway up` and our code will automatically be deployed to our project.

![A demo of our cron service running on Railway](https://cms.railway.com/media/a507284743c5c63482f6594c00037571e032fa45f8293d2b9966b1a9802c01ed.png)

As you can see in the screenshot above, our cron job is run every minute as specified in our code. Everything was automatically built and deployed with no additional configuration needed.

## Demo + Template

You can [click here](https://railway.com/project/1f7ff487-f8e4-4002-b4c7-4267954d2ea2) a live demo of the project we just deployed or click the button below to deploy your own in just one click!

[https://railway.com/new/template/KViDnA](https://railway.com/new/template/KViDnA)

## Closing

We hope this post helps anyone looking to deploy cron jobs on Railway and would love for people to contribute similar tutorials in other languages and frameworks. Feel free to reach out to us on [Discord](https://discord.gg/railway) if you’re interested.