---
title: "Deploy Xata PostgreSQL + Node.js + Drizzle"
description: "Deploy and Host Xata PostgreSQL + Node.js + Drizzle with Railway"
category: "Storage"
url: https://railway.com/deploy/xata-postgresql-nodejs-drizzle
---

# Deploy Xata PostgreSQL + Node.js + Drizzle

Deploy and Host Xata PostgreSQL + Node.js + Drizzle with Railway

**[Deploy Xata PostgreSQL + Node.js + Drizzle on Railway](https://railway.com/template/xata-postgresql-nodejs-drizzle)**

- **Creator:** Xata
- **Category:** Storage
- **Total deploys:** 15
- **Verified:** Yes

## Template content

### Node.js with Xata https://xata.io/images/xata-brand-assets/logo-symbol/logo-square.svg

- **Source:** https://github.com/xataio/railway-nodejs-drizzle-xata
- **Public domain:** Yes

## Documentation

# Deploy and Host Xata PostgreSQL + Node.js + Drizzle on Railway

Xata is a fully-managed PostgreSQL service offering advanced features like:

- Copy-on-Write branching
- Point-in-Time (PITR) recovery
- Separation of storage from compute
- High availability, redundancy, and scalability
- Long list of PostgreSQL extensions, including pgvector, postgis, pg_cron, etc.
- Built-in query editor, AI self-optimizations, advanced observability
- Expert support in PostgreSQL

## About Hosting Xata PostgreSQL with Railway

This template contains a sample Node.js application configured to use Drizzle ORM to connect to the Xata PostgreSQL service. You can use this template, or simply follow the same pattern in your own application. 

This template is for Node.js, but Xata PostgreSQL can be used with any programming language or framework that supports PostgreSQL.

The `DATABASE_URL` is the only environment variable required. Set it to the PostgreSQL connection string, which you can copy from the branch overview page in the Xata console.

## Common Use Cases

- A fully-managed PostgreSQL database to store all your data: users, organizations, workspaces, etc.
- Implement infinite chat history and memory for your AI agent. Works with any AI framework that uses PostgreSQL.
- Use the `pgvector` extension to create similarity search, product recommendations, or AI RAG use cases.

## Dependencies for Xata + Node.js + Drizzle Hosting

- **Xata account**: You can create one by logging in at [console.xata.io](http://console.xata.io) . Once you login, create an organization, and a project inside the organization. Start a `main` branch for your database. From the branch overview page, copy the connection string set the `DATABASE_URL` to it.

### Deployment Dependencies

- Drizzle, which is already included in the template.

## Implementation Details

This is the minimal code to instantiate Drizzle and use together with Xata:

```
const { drizzle } = require("drizzle-orm/postgres-js");
const postgres = require("postgres");

// Database connection configuration
const client = postgres(process.env.DATABASE_URL);
const db = drizzle(client);

module.exports = { db, client };
```

Then in a route you can execute SQL like this:

```jsx
const { db } = require("../config/database");
const result = await db.execute("SELECT version()");
```

Set the `DATABASE_URL` in your Railway project settings, and you are good to go.

## Why Deploy Xata PostgreSQL with Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By using Xata PostgreSQL together with Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/xata-postgresql-nodejs-drizzle
