Primary API functions for collecting and formatting environment information programmatically.
Main programmatic interface for collecting environment information with support for presets and custom configurations.
/**
* Main programmatic interface for collecting environment information
* @param args - Configuration object specifying what to collect, or preset name
* @param options - Collection and formatting options
* @returns Promise<string> - Formatted environment information
*/
function run(args, options);Usage Examples:
const envinfo = require('envinfo');
// Using default configuration
const result = await envinfo.run();
// Using specific configuration
const result = await envinfo.run({
System: ['OS', 'CPU', 'Memory'],
Binaries: ['Node', 'npm'],
Browsers: ['Chrome', 'Firefox']
}, {
json: true
});
// Using preset
const result = await envinfo.run({ preset: 'react-native' });
// Using preset name directly
const result = await envinfo.run('react-native');Core orchestration function that manages the collection of environment data based on configuration.
/**
* Core function that orchestrates environment data collection
* @param props - Configuration object specifying which information to collect
* @param options - Formatting and collection options
* @returns Promise<string> - Formatted environment report
*/
function main(props, options);Usage Examples:
const envinfo = require('envinfo');
// Collect system and binary information
const result = await envinfo.main({
System: ['OS', 'CPU', 'Memory'],
Binaries: ['Node', 'npm', 'Yarn']
}, {
json: true,
console: false
});
// Collect all default information
const result = await envinfo.main({}, { markdown: true });
// Collect specific packages
const result = await envinfo.main({
npmPackages: ['react', 'react-dom', 'webpack']
}, {
duplicates: true,
showNotFound: true
});Command-line interface handler that processes parsed command-line options and executes appropriate collection.
/**
* CLI interface handler for processing command-line options
* @param options - Parsed command-line options from minimist or similar
* @returns Promise<string> - Formatted environment report
*/
function cli(options);Usage Examples:
const envinfo = require('envinfo');
const minimist = require('minimist');
// Parse command line arguments
const argv = minimist(process.argv.slice(2));
argv.console = true;
// Execute CLI functionality
const result = await envinfo.cli(argv);
// Example CLI options object structure:
const cliOptions = {
system: true, // --system flag
browsers: true, // --browsers flag
json: true, // --json flag
console: true, // Enable console output
all: false, // --all flag
preset: 'jest', // --preset jest
helper: 'Node' // --helper Node (run specific helper)
};Direct access to all helper functions for custom environment detection.
/**
* Object containing all helper functions organized by category
* Each helper returns Promise<[name, version, path?]> or Promise<[name, 'Not Found']>
*/
const helpers = {
// System helpers
getOSInfo: () => Promise<[string, string]>,
getCPUInfo: () => Promise<[string, string]>,
getMemoryInfo: () => Promise<[string, string]>,
getContainerInfo: () => Promise<[string, string]>,
getShellInfo: () => Promise<[string, string]>,
// Binary helpers
getNodeInfo: () => Promise<[string, string, string?]>,
getnpmInfo: () => Promise<[string, string, string?]>,
getYarnInfo: () => Promise<[string, string, string?]>,
// ... all other helpers
};Usage Examples:
const { helpers } = require('envinfo');
// Get specific system information
const [name, osInfo] = await helpers.getOSInfo();
console.log(`${name}: ${osInfo}`);
// Get Node.js version and path
const [name, version, path] = await helpers.getNodeInfo();
console.log(`${name}: ${version} - ${path}`);
// Check for specific browser
const [browserName, browserVersion] = await helpers.getChromeInfo();
if (browserVersion !== 'Not Found') {
console.log(`Chrome ${browserVersion} is installed`);
}interface EnvironmentConfig {
System?: string[]; // System information categories
Binaries?: string[]; // Binary tools to detect
Managers?: string[]; // Package managers to detect
Utilities?: string[]; // Development utilities to detect
Servers?: string[]; // Web servers to detect
Virtualization?: string[]; // Virtualization tools to detect
SDKs?: string[]; // SDKs to detect
IDEs?: string[]; // IDEs and editors to detect
Languages?: string[]; // Programming languages to detect
Databases?: string[]; // Databases to detect
Browsers?: string[]; // Browsers to detect
Monorepos?: string[]; // Monorepo tools to detect
npmPackages?: string | string[] | boolean; // Local npm packages
npmGlobalPackages?: string | string[] | boolean; // Global npm packages
}interface CollectionOptions {
json?: boolean; // Output in JSON format
markdown?: boolean; // Output in Markdown format
console?: boolean; // Print to console (default true for CLI)
duplicates?: boolean; // Show duplicate package versions in parentheses
fullTree?: boolean; // Traverse entire node_modules dependency tree
showNotFound?: boolean; // Include "Not Found" results in output
title?: string; // Add a title to the report
preset?: string; // Use a predefined preset
helper?: string; // Run a specific helper function only
all?: boolean; // Collect all available information
raw?: string; // Raw JSON configuration string
}All core functions return formatted strings, while helpers return structured arrays:
// Core functions return formatted output
type CoreFunctionResult = string;
// Helper functions return structured data
type HelperResult =
| [string, string] // [name, version]
| [string, string, string] // [name, version, path]
| [string, 'Not Found'] // [name, 'Not Found']
| [string, 'N/A']; // [name, 'N/A'] for unsupported platformsCore functions handle errors gracefully: