# Set up Relia in a Node.js or Express app

> One command adds Relia to a Node.js server (Express, Fastify, NestJS, Koa, Hapi, Hono) so its requests, errors and database calls show up in Relia.

Section: Set up your stack · Page: https://tryrelia.com/docs/node-express-setup · Last checked against the product: 2026-11-01
Video walkthrough: https://youtu.be/ssyz73SYNQ0

This page sets Relia up by hand from a terminal. To have your AI assistant do it instead, see [Set up Relia with your AI assistant](https://tryrelia.com/docs/setup-with-ai-assistant.md).

## Before you start

- A Relia account ([Create your account](https://tryrelia.com/docs/create-account.md)).
- A terminal open in your server's folder (the one with its `package.json`).

## Steps

1. **Run the setup:**

   ```bash
   npx relia-sdk@latest init
   ```

   Always use `relia-sdk`: the npm package called `relia` belongs to someone else.

2. **Sign in.** Choose the browser option, copy the token from the **CLI Authentication** page, and paste it back into the terminal.

3. **Choose what to set up.** The setup finds your server framework (for example *Express API*). Choose **Everything Relia found here**.

4. **Pick your Relia project**, or create one right there.

5. **Answer "Tell Relia who your users are?"** Say yes if your app has sign-in. The setup then prints the lines to add; see [Identify your users](https://tryrelia.com/docs/identify-users.md).

   > **Tip:** watch [See which customers a bug hit: identify users in Relia](https://youtu.be/1mIOiHnI9nk) (2 min).

6. **Check what it wrote:**
   - A new `relia.tracing.js` with your project's id and key.
   - One line at the top of your entry file (the file `npm start` runs) that loads it first, for example `require('./relia.tracing');` (the path depends on where your entry file is).
   - For Express: Relia's middleware after `const app = express()`, and its error handler after your routes.
   - `relia-sdk` added to your `package.json`.

7. **Restart your app** and call one of its endpoints. The console says `tracing initialized`.

## Set it up by hand instead

If you'd rather write the code yourself, install the package:

```bash
npm install relia-sdk
```

Create `relia.tracing.js` (your project's id and key are on your project page under **Setup Guide & SDK**):

```js
require("relia-sdk/node").start({
  serviceName: "my-api",
  projectId: "<your project id>",
  key: "<your project key>",
})
```

Load it as the very first line of your entry file, before any other import:

```js
require("./relia.tracing")   // ESM: import "./relia.tracing.js"
```

For Express, add the middleware and the error handler:

```js
const relia = require("relia-sdk/node")

app.use(relia.expressMiddleware())
// ... your routes ...
app.use(relia.expressErrorHandler()) // after your routes: records errors with their stack trace
```

## What Relia records

- Every request with its route, status and time: Express, Fastify, NestJS, Koa and Hapi.
- Errors with their stack traces.
- Outgoing HTTP and `fetch` calls.
- Database calls (PostgreSQL, MongoDB, MySQL, Redis), with values removed.
- Queue jobs (BullMQ, SQS, Kafka) and GraphQL.
- Warnings and errors from `console.warn`, `console.error`, winston and bunyan, as log lines. Set `RELIA_LOGS=0` to turn this off.
- Calls to AI models in your product. See [Monitor AI calls in your app](https://tryrelia.com/docs/ai-calls-setup.md).

Running several services in one project? Give each its own `serviceName`. Relia draws how they call each other on the **Map**.

## When you deploy

Your project's id and key are inside `relia.tracing.js`, so your host needs no extra environment variable. Just deploy as usual.

## Check it worked

Open your project in Relia and go to the **Setup** tab. **Requests from your server** changes from *Not yet* to *Arriving*, usually within a minute. Your requests and errors appear under **APIs**, and your queries under **Database**.

## If something's wrong

- **Still "Not yet" after a few minutes:** make sure `relia.tracing` is loaded before anything else in your entry file, restart the app and call an endpoint again. Then see [Relia shows no data](https://tryrelia.com/docs/no-data.md).
- **Errors show without a stack trace (Express):** `expressErrorHandler()` must come after your routes.
- **The setup refused to create a project:** it shows the reason and offers your existing projects. Pick one of them.

## Next

- [Identify your users](https://tryrelia.com/docs/identify-users.md)
- [Watch your web app](https://tryrelia.com/docs/web-app-setup.md)
- [Teach Relia what matters](https://tryrelia.com/docs/teach-relia.md)
- [Set up a Next.js app](https://tryrelia.com/docs/nextjs-setup.md)

---
All Relia docs for AI assistants: https://tryrelia.com/llms.txt (index) · https://tryrelia.com/llms-full.txt (everything in one file)
