npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongodbautoip

v1.0.4

Published

Automatically update MongoDB Atlas IP whitelist when server ip changes, and delete the old ones.

Downloads

31

Readme

MongoDBAutoIP

Automatically update MongoDB Atlas IP whitelist when server ip changes, and delete the old ones.

Features

  • Automatically fetches the current server's IP address.
  • Adds the current IP address to the MongoDB Atlas whitelist.
  • Removes outdated IP addresses from the whitelist. (can set in ipUtils.js whitelist_retention_period, currently 24hrs.)
  • Handles authentication with MongoDB Atlas API, using the HTTP Digest.

Why

Locking down your database to only in use IPs is one of the #1 security rules. When using shared environments, the IP address is not static and in platforms like heroku it changes several times a day. You can either enable 0.0.0.0/0 which allows all connections (bad), or use a solution like Fixie (https://usefixie.com/), or Quotaguard (https://www.quotaguard.com/) which can be tougher to scale for an indiehacker with no revenue. Simpler scripts could be written in the past using request or digest-fetch, but those are depricated so I've built that in.

Installation

Install the module using npm:

npm install mongoDBAutoIP

Usage Instructions:

1. Add the following to your app.js file.

require('dotenv').config();
const mongoDBAutoIP = require('mongodbautoip'); require('dotenv').config();


const publicKey = process.env.ATLAS_API_PUBLIC; // add to .env or Config Vars
const privateKey = process.env.ATLAS_API_PRIVATE; // add to .env or Config Vars

const config = {
    projectId: process.env.ATLAS_PROJECT_ID,
    publicKey: publicKey,
    privateKey: privateKey,
    username: publicKey,
    password: privateKey,
}


// After Port set/defined, 
const { checkAndUpdateIP } = mongoDBAutoIP.setup(config);

checkAndUpdateIP().then(() => {
  http.listen(port, () => {
    console.log(`Server is running on port ${port}`);
  });
}).catch(error => {
  console.error('Failed to update IP whitelist on startup:', error);
  // Even if IP update fails, you might still want to start the server
  http.listen(port, () => {
    console.log(`Server is running on port ${port}`);
  });
});

2. Get Project ID and API Keys:

  • Login to MongoDB Atlas (https://cloud.mongodb.com/)
  • Click the access manager dropdown in the header next to your organization name.
  • On the far right click the "Create API Key" button.
  • Give it all permissions (needs personal read/write).
  • Copy your public and private keys and add them to your .env or Config Vars like this:
  ATLAS_API_PUBLIC = myPUBLICapikey
  ATLAS_API_PRIVATE = myPRIVATEapikey
  • On the left sidebar on the organization page, click projects. Now on the far right, click the ellipses (...) button and "Copy Project ID".
  • add your project ID to your .env or Config Vars like this:
  projectId = myPROJECTid

Additional Notes

  • To adjust the whitelist_retention_period, go to lib/apiUtils.js and change the following (may add to options in the future):
const WHITELIST_RETENTION_PERIOD = 24 * 60 * 60 * 1000; //Currently 24hrs

About the Author

  • Find me on https://twitter.com/BuildnBootstrap
  • Working on https://www.jobflows.com/
  • Tip - ETH 0x35195758d35C4E407041E484cc16bE67397ABf3c