---
title: "Legacy SDK"
url: https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/
---

# Legacy SDK | Sentry for Node.js

##### Deprecation Warning

A new Node SDK has superseded this deprecated version. Sentry preserves this documentation for customers using the old client. We recommend using the [updated Node SDK](https://docs.sentry.io/platforms/javascript/guides/node.md) for your projects.

##### Note

If you’re using JavaScript in the browser, you’ll need [sentry-javascript](https://docs.sentry.io/platforms/javascript.md).

## [Installation](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#installation)

Raven is distributed via `npm`:

```bash
npm install raven --save
```

## [Configuring the Client](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#configuring-the-client)

Next you need to initialize the Raven client and configure it to use your Sentry DSN:

```javascript
var Raven = require("raven");
Raven.config("___PUBLIC_DSN___").install();
```

At this point, Raven is set up to capture and report any uncaught exceptions.

You can optionally pass an object of configuration options as the 2nd argument to *Raven.config*. For more information, see [*Configuration*](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/config.md).

## [Reporting Errors](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#reporting-errors)

Raven’s `install` method sets up a global handler to automatically capture any uncaught exceptions. You can also report errors manually with `try...catch` and a call to `captureException`:

```javascript
try {
  doSomething(a[0]);
} catch (e) {
  Raven.captureException(e);
}
```

You can also use `wrap` and `context` to have Raven wrap a function and automatically capture any exceptions it throws:

```javascript
Raven.context(function () {
  doSomething(a[0]);
});
```

For more information on reporting errors, see [*Usage*](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/usage.md).

## [Adding Context](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#adding-context)

Code run via `wrap` or `context` has an associated set of context data, and Raven provides methods for managing that data.

You’ll most commonly use this to associate the current user with an exception:

```javascript
Raven.context(function () {
  Raven.setContext({
    user: {
      email: "matt@example.com",
      id: "123",
    },
  });
  // errors thrown here will be associated with matt
});
// errors thrown here will not be associated with matt
```

This can also be used to set `tags` and `extra` keys for associated tags and extra data.

You can update the context data with `mergeContext` or retrieve it with `getContext`. When an exception is captured by a wrapper, the current context state will be passed as options to `captureException`.

See [context/wrap](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/usage.md#raven-node-additional-context) for more.

## [Breadcrumbs](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#breadcrumbs)

Breadcrumbs are records of server and application lifecycle events that can be helpful in understanding the state of the application leading up to a crash.

We can capture breadcrumbs and associate them with a context, and then send them along with any errors captured from that context:

```javascript
Raven.context(function () {
  Raven.captureBreadcrumb({
    message: "Received payment confirmation",
    category: "payment",
    data: {
      amount: 312,
    },
  });
  // errors thrown here will have breadcrumb attached
});
```

Raven can be configured to automatically capture breadcrubs for certain events including:

> * http/https requests
> * console log statements
> * postgres queries

For more information, see [Recording Breadcrumbs](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/usage.md#raven-recording-breadcrumbs).

## [Dealing with Minified Source Code](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#dealing-with-minified-source-code)

Raven and Sentry support [Source Maps](https://web.dev/articles/source-maps). If you provide source maps in addition to your minified files that data becomes available in Sentry. For more information see [Source Maps](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/sourcemaps.md).

## [Middleware and Integrations](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#middleware-and-integrations)

If you’re using Node.js with a web server framework/library like Connect, Express, or Koa, it is recommended to configure one of Raven’s server middleware integrations. See [*Integrations*](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md).

## [Deep Dive](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk.md#deep-dive)

For more detailed information about how to get most out of Raven there is additional documentation available that covers all the rest:

* [Configuration](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/config.md)

* [Usage](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/usage.md)

* [Integrations](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md)

  * [Connect](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md#connect)
  * [Express](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md#express)
  * [Koa](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md#koa)
  * [Loopback](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md#loopback)
  * [Sails](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md#sails)

* [Source Maps](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/sourcemaps.md)

* [TypeScript](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/typescript.md)

* [CoffeeScript](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/coffeescript.md)

Resources:

* [Bug Tracker](https://github.com/getsentry/sentry-javascript/issues)
* [GitHub Project](https://github.com/getsentry/sentry-javascript)

## Pages in this section

- [Usage](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/usage.md)
- [Source Maps](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/sourcemaps.md)
- [TypeScript](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/typescript.md)
- [CoffeeScript](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/coffeescript.md)
- [Configuration](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/config.md)
- [Integrations](https://docs.sentry.io/platforms/javascript/guides/node/legacy-sdk/integrations.md)
