> ## Documentation Index
> Fetch the complete documentation index at: https://docs.traceback.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript & Node.js SDK

> Instrument Node.js, Express, Fastify, and NestJS applications with Traceback.

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @traceback/node
  ```

  ```bash pnpm theme={null}
  pnpm add @traceback/node
  ```

  ```bash yarn theme={null}
  yarn add @traceback/node
  ```
</CodeGroup>

***

## Basic Configuration

Initialize Traceback at the absolute top of your application entry point before importing other libraries:

```typescript theme={null}
import * as Traceback from "@traceback/node";

Traceback.init({
  dsn: process.env.TRACEBACK_DSN,
  environment: process.env.NODE_ENV || "production",
  release: "backend@1.2.0",
  tracesSampleRate: 1.0,
});
```

***

## Express Middleware

```typescript theme={null}
import express from "express";
import * as Traceback from "@traceback/node";

const app = express();

// Request handler must be the first middleware on the app
app.use(Traceback.Handlers.requestHandler());
app.use(Traceback.Handlers.tracingHandler());

app.get("/api/user", (req, res) => {
  res.json({ status: "ok" });
});

// The error handler must be before any other error middleware and after all controllers
app.use(Traceback.Handlers.errorHandler());

app.listen(3000);
```

***

## User Context & Tags

```typescript theme={null}
Traceback.setUser({
  id: "usr_123",
  email: "developer@example.com",
  role: "admin",
});

Traceback.setTag("region", "eu-central-1");
```
