Node Modules CLI and Library
The `node-modules` package provides both a command-line interface (CLI) tool and a Node.js module for searching `node-modules.com`. Its primary functionality involves querying the site for packages, with an option to personalize results based on GitHub follows or stars. The current stable version is 1.0.1. Given its age and reliance on `node-modules.com` (which is no longer a primary source for package discovery, superseded by npmjs.com), the package has likely ceased active development. It does not appear to follow a regular release cadence and is designed for an ecosystem context that has largely evolved, making its key differentiator (integration with `node-modules.com`) less relevant today.
Common errors
-
node-modules: command not found
cause The `node-modules` CLI tool was not installed globally or is not in your system's PATH.fixInstall the package globally using `npm install -g node-modules`. -
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require('node-modules')` inside an ES Module (ESM) file (e.g., a `.mjs` file or a `.js` file in a `"type": "module"` project).fixUse `const search = await import('node-modules');` or convert your file to CommonJS. However, given the package's design, using it in modern ESM projects is generally discouraged. -
Error: connect ECONNREFUSED <ip-address>:<port>
cause The `node-modules` package tried to connect to `node-modules.com` but the connection was refused. This typically indicates the server is offline, unreachable, or has been shut down.fixThis issue is inherent to the dependency on a potentially defunct external service. There is no code-level fix for this specific package. You must use alternative package discovery methods.
Warnings
- breaking The package relies on the `node-modules.com` website for search functionality. As of current information, this website is either defunct or no longer actively maintained, making the core functionality of this package effectively broken.
- gotcha The `node-modules` package is written exclusively in CommonJS (CJS) and does not natively support ES Modules (ESM) syntax. Attempting to `import` it in an ESM context will lead to module resolution errors.
- gotcha The package has not been updated since 2014, meaning it may contain outdated dependencies or security vulnerabilities, and is unlikely to receive patches for newly discovered issues.
Install
-
npm install node-modules -
yarn add node-modules -
pnpm add node-modules
Imports
- search
import search from 'node-modules';
const search = require('node-modules'); - NodeModulesCLI
import { NodeModulesCLI } from 'node-modules';require('node-modules/cli'); // or similar for programmatic CLI access - stream
const { stream } = require('node-modules');search('query').on('data', handler);
Quickstart
const search = require('node-modules');
// Search for 'test framework' packages
// Replace 'mafintosh' with your GitHub username if personalizing.
const stream = search('test framework', { username: 'mafintosh' });
console.log('Searching for packages...');
stream.on('data', function(result) {
// result is an object containing package information
console.log(`- ${result.name} (v${result.version || 'N/A'}): ${result.description || 'No description'}`);
});
stream.on('end', function() {
console.log('--- Search complete. No more results. ---');
});
stream.on('error', function(err) {
console.error('An error occurred during search:', err.message);
if (err.message.includes('ECONNREFUSED') || err.message.includes('ENOTFOUND')) {
console.error('This might be due to node-modules.com being unavailable or unreachable.');
}
});