Static IP guide

Connecting to MongoDB with a static IP from a Node app on Heroku

MongoDB Atlas rejects connections from addresses outside its IP Access List, and adding 0.0.0.0/0 to make Heroku work defeats the point of the list. The MongoDB Node.js driver has native SOCKS proxy support, so Mongoose can route through Fixie Socks with four extra connection options and no tunnel process.

RuntimeNode.js and JavaScript
PlatformHeroku
DestinationMongoDB
Fixie productFixie Socks Heroku add-on

Recommended setup

Use Fixie Socks Heroku add-on for MongoDB connections from a deployment environment with changing outbound IPs. Store the proxy value in FIXIE_SOCKS_HOST, then configure Node.js to route outbound traffic through Fixie before connecting to MongoDB.

Set up Fixie on Heroku

Heroku is a native Fixie marketplace flow. Install the Fixie Socks Heroku add-on or attach it from the Heroku CLI. Heroku will create FIXIE_SOCKS_HOST as a config var for the app.

Attach fixie-socks to your Heroku app

heroku addons:create fixie-socks
heroku config:get FIXIE_SOCKS_HOST

Implementation

The example below shows the core application-side change. Keep credentials in environment variables and avoid committing proxy, database, or API secrets.

Connect to MongoDB through FIXIE_SOCKS_HOST

const mongoose = require('mongoose');

const fixieValues = process.env.FIXIE_SOCKS_HOST.split(new RegExp('[/(:\\/@)/]+'));

mongoose.connect(process.env.MONGODB_URI, {
  proxyUsername: fixieValues[0],
  proxyPassword: fixieValues[1],
  proxyHost: fixieValues[2],
  proxyPort: Number(fixieValues[3]),
}).then(() => {
  console.log('Connected to MongoDB');
});

Good to know

  • Add both Fixie IPs to Atlas under Network Access → IP Access List, then remove any broad CIDR entries you added as a workaround.
  • The proxy options work with standard and mongodb+srv connection strings alike; SRV resolution happens over DNS before the proxied TCP connection is opened.
  • Native driver SOCKS support arrived in the 4.x series — if you are pinned to an old 3.x driver, upgrade before wiring in the proxy options.

Allowlist and test the static IPs

  1. Open the Fixie dashboard and copy the outbound IP addresses for this proxy.
  2. Add both IPs to the MongoDB network access list.
  3. Deploy the updated Node.js app on Heroku.
  4. Run a small connection test before sending production traffic.

Related guides

Related docs