Registry / devops / is-mongodb-running

is-mongodb-running

JSON →
library1.0.2jsnpmunverified

A CLI tool and Node.js library (v1.0.2) that checks if MongoDB is running on the system, reports the port and PID of each instance. Works with callback or promises, supports CLI flags for port/PID filtering and JSON output. Lightweight with no external dependencies; simple and focused.

npm install is-mongodb-running
INSTALL
IMPORT
SIG · IS-MONGODB-RUNNING
I
is-mongodb-running
devopsjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

is-mongodb-running (default export)
const isRunning = require('is-mongodb-running');
import isRunning from 'is-mongodb-running';
This package is CommonJS-only; ESM import will fail.
Promise-based API
const promise = require('is-mongodb-running/promise');
import { promise } from 'is-mongodb-running';
Promise version is at a separate subpath; named export does not exist.
CLI usage
npx is-mongodb-running
CLI is available when installed globally or via npx.

Checks if MongoDB is running locally and logs the port and PID of each instance using callback API.

const isRunning = require('is-mongodb-running'); isRunning((err, instances) => { if (err) { console.error('Error:', err); return; } if (instances.length === 0) { console.log('No MongoDB instances running'); } else { instances.forEach(({ pid, port }) => { console.log(`MongoDB running on port ${port} with PID ${pid}`); }); } });
Debug
Known issues
gotchaOnly checks for MongoDB on localhost; does not connect to remote hosts.
fix
Use MongoDB connection method (e.g., mongoose.connect) for remote checks.
affects: >=1.0
gotchaDepends on OS-specific commands (e.g., 'ps', 'lsof') and may not work on all platforms or restricted environments.
fix
Ensure required system utilities are available; consider using Docker or a more robust monitoring solution for cross-platform support.
affects: >=1.0
gotchaCLI --json flag outputs to stdout, but library returns array directly; mixing both can lead to confusion.
fix
Use --json flag only in CLI context; library function already returns structured data.
affects: >=1.0
Errors
Common errors & fixes
Error: Command failed: lsof -iTCP:27017 -sTCP:LISTEN -P -n
lsof not installed or not permitted on the system (e.g., Alpine Linux, restricted container).
fix
Install lsof (e.g., apt-get install lsof or apk add lsof) or run as root/user with sufficient privileges.
TypeError: isRunning is not a function
Using ESM import statement with a CommonJS module; package does not support ES modules.
fix
Use require() instead: const isRunning = require('is-mongodb-running');
Cannot find module 'is-mongodb-running/promise'
Promise subpath not resolved properly; Node.js version may be too old for subpath exports support.
fix
Use Node.js >=12 or use callback API.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
is-mongodb-running — npm install is-mongodb-running · libregistry