Using a proxy

Information for Node.js applications running in environments that need to route outbound traffic through a proxy.

This documentation is for version 7+ of the BugSnag JavaScript notifier. If you are using older versions, we recommend upgrading to the latest release using our Upgrade guide. Documentation for the previous release can be found on our legacy pages.

Specify an agent

In Node.js, the delivery mechanism uses the core http/https modules to send error reports. When you set the agent option, BugSnag will pass it through when it constructs the underlying request. This means you can supply a preconfigured agent for the type of proxy you’re using:

Examples

Sending via an HTTP/HTTPS proxy

Install the HTTPS agent from npm:

npm install --save https-proxy-agent

Configure the agent and pass it in to BugSnag:

const ProxyAgent = require('https-proxy-agent')
const agent = new ProxyAgent('http://your-proxy:3218')
Bugsnag.start({
  apiKey: 'YOUR_API_KEY',
  agent: agent
})

If you want to send reports to an insecure (HTTP) endpoint, you’ll need to use the http-proxy-agent instead. However, using the HTTPS endpoint is strongly encouraged!

Sending via a SOCKS proxy

Install the socks agent from npm:

npm install --save socks-proxy-agent

Configure the agent and pass it in to BugSnag:

const ProxyAgent = require('socks-proxy-agent')
const agent = new ProxyAgent('socks://your-proxy:9050')
Bugsnag.start({
  apiKey: 'YOUR_API_KEY',
  agent: agent
})

Basic authentication (and more)

If your proxy server requires authentication or you want finer-grained control over the agent’s behaviour, you’ll need to pass in an options object rather than a URL to the proxy agent:

const url = require('url')
const opts = url.parse('http://your-proxy:3218')

// set credentials
opts.auth = 'username:password'

Bugsnag.start({
  apiKey: 'YOUR_API_KEY',
  agent: new ProxyAgent(opts)
})