Using a proxy

This documentation is for version 6 of the BugSnag JavaScript notifier. We recommend upgrading to the latest release using our Upgrade guide. Documentation for the current release can be found here.

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

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({
  apiKey: 'YOUR_API_KEY',
  agent: agent
})

Note: 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({
  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({
  apiKey: 'YOUR_API_KEY',
  agent: new ProxyAgent(opts)
})