# Turso + Railway

> Deploy a JavaScript/Rust app using [Turso Cloud embedded replicas](/features/embedded-replicas) to [Railway](https://railway.app/).
> Canonical HTML: https://tursodb.cn/docs/features/embedded-replicas/with-railway/
> Upstream Source (MIT): https://docs.turso.tech/features/embedded-replicas/with-railway
> Language: en

---
![Koyeb banner](/images/turso-docs/platforms/railway-banner.png)

## Prerequisites

Before you start, make sure you:

* [Install the Turso CLI](/docs/cli/installation/)
* [Sign up or login to Turso Cloud](/docs/cli/authentication/#signup)
* [Install the Railway CLI](https://docs.railway.app/guides/cli#installing-the-cli)

**1. Retrieve database credentials**

You will need an existing database to continue. If you don't have one, [create one](/docs/quickstart/).

Get the database URL:

```bash
turso db show --url <database-name>
```

Get the database authentication token:

```bash
turso db tokens create <database-name>
```

Assign credentials to the environment variables inside `.env`.

```bash
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

You will want to store these as environment variables.

</div></div>


**2. Get application code**

Fork and clone the following embedded replica project from GitHub locally:

<div class="doc-cards">
<a class="doc-card" href="https://github.com/tursodatabase/embedded-replicas-with-js" target="_blank" rel="noopener noreferrer"><div class="doc-card-title"><span>My Expenses Tracker - (Elysia + Bun)</span><span class="doc-card-arrow" aria-hidden="true">↗</span></div><p class="doc-card-desc">See the full source code</p></a>
<a class="doc-card" href="https://github.com/tursodatabase/embedded-replicas-with-rust" target="_blank" rel="noopener noreferrer"><div class="doc-card-title"><span>Web Traffic API - (Rust)</span><span class="doc-card-arrow" aria-hidden="true">↗</span></div><p class="doc-card-desc">See the full source code</p></a>
</div>


**3. Create a new Railway project**

Run the following command to create a new Railway project. Provide the project's name when prompted.

```bash
railway init
```

**4. Add a service to the Railway project**

[Create a new empty service](https://docs.railway.app/guides/services#creating-a-service) on your Railway project to act as your app's deployment target.

**5. Link application to service**

Run the following command to list and select the service to link to your application:

```bash
railway service
```

**6. Add database credentials**

Open the service on your Railway dashboard and add your Turso Cloud database credentials.

```bash
TURSO_DATABASE_URL=libsql://[db-name]-[github-username].turso.io
TURSO_AUTH_TOKEN=...
LOCAL_DB=file:local-db-name.db
```

**7. Deploy**

Run the following command to deploy your application:

```bash
railway up
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

Make sure you [expose your application to the internet](https://docs.railway.app/guides/public-networking) to make it accessible from the public network.

</div></div>


<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">WARNING</div><div class="doc-callout-body">

If you are on a free plan, you'll need to connect your Railway account to GitHub to have access to code deployments.

</div></div>
