envinfo

repository·main·Indexed 21 days ago

https://github.com/tabrindle/envinfo

A utility and library for generating comprehensive reports of a developer's environment to troubleshoot 'it works on my machine' issues. It collects details on operating systems, binary versions, installed languages, IDEs, SDKs, and npm packages. Available as a CLI tool with various filtering flags and output formats (Markdown, JSON), or as a programmatic library via the run() method and specialized helpers.

Tokens
2.4K
Snippets
8
Records
10
Agent score
74%

What's inside envinfo

  1. Install envinfo

    main

    You can install envinfo as a CLI tool or use it as a library in your project.

    As a CLI tool

    Install it globally to use the envinfo command anywhere:

    npm install -g envinfo || yarn global add envinfo

    Alternatively, run it without installation using npx:

    npx envinfo

    As a library

    Install it as a dependency in your project:

    npm install envinfo || yarn add envinfo
    npm install -g envinfo || yarn global add envinfo
  2. Use the envinfo CLI to generate environment reports

    main

    The envinfo CLI allows you to generate detailed reports of your development environment, including system specs, installed SDKs, languages, and package managers. You can run it directly via envinfo or using npx.

    To generate a report, run the command without arguments to get a default report, or specify flags to include specific categories of information.

    # Run via npx
    npx envinfo
    
    # Or if installed globally
    envinfo
  3. Use envinfo programmatically with run()

    main

    The envinfo.run() method takes a configuration object defining which categories to collect and an options object for formatting. It returns a Promise that resolves to a string (formatted as markdown, JSON, or YAML depending on options).

    Configuration Object Keys:

    • System: e.g., ['OS', 'CPU']
    • Binaries: e.g., ['Node', 'Yarn', 'npm']
    • Browsers: e.g., ['Chrome', 'Firefox', 'Safari']
    • npmPackages: e.g., ['styled-components', 'babel-plugin-styled-components']

    Options Object Keys:

    • json: boolean (set to true for JSON output)
    • showNotFound: boolean
    • markdown: boolean
    • yaml: boolean
    import envinfo from 'envinfo';
    
    envinfo.run(
        {
            System: ['OS', 'CPU'],
            Binaries: ['Node', 'Yarn', 'npm'],
            Browsers: ['Chrome', 'Firefox', 'Safari'],
            npmPackages: ['styled-components', 'babel-plugin-styled-components'],
        },
        { json: true, showNotFound: true }
    ).then(env => console.log(env));
  4. Use envinfo helpers for specific info

    main

    If you only need specific information, you can use the exported helpers. Each helper returns a Promise that resolves to an array of values: ["Name", "Version", "Path"] (or similar depending on the helper).

    Example for Node.js info:

    const envinfo = require('envinfo');
    
    // each helper returns a promise
    const node = await envinfo.helpers.getNodeInfo();
    
    // The promises resolve to an array of values: ["Name", "Version", "Path"]
    // e.g. ["Node", "10.9.0", "/usr/local/bin/node"]
    
    console.log(`Node: ${node[1]} - ${node[2]}`); // "Node: 10.9.0 - ~/.nvm/versions/node/v8.14.0/bin/node"
  5. CLI Options for envinfo

    main

    Use the following flags to filter or format the CLI output:

    FlagDescription
    --systemPrint general system info such as OS, CPU, Memory and Shell
    --browsersGet version numbers of installed web browsers
    --SDKsGet platforms, build tools and SDKs of iOS and Android
    --IDEsGet version numbers of installed IDEs
    --languagesGet version numbers of installed languages such as Java, Python, PHP, etc
    --binariesGet version numbers of node, npm, watchman, etc
    --npmPackagesGet version numbers of locally installed npm packages (glob, string, or comma delimited list)
    --npmGlobalPackagesGet version numbers of globally installed npm packages
    --duplicatesMark duplicate npm packages inside parentheses eg. (2.1.4)
    --fullTreeTraverse entire node_modules dependency tree, not just top level
    --markdownPrint output in markdown format
    --jsonPrint output in JSON format
    --consolePrint to console (defaults to on for CLI, off for programmatic usage)
  6. Use envinfo CLI

    main

    The envinfo CLI generates a report of your system details, including OS, binaries, managers, utilities, servers, virtualization, SDKs, IDEs, languages, databases, browsers, and npm packages.

    Run the command to see a default report:

    envinfo

    Or use npx:

    npx envinfo
    npx envinfo
  7. Use envinfo as a unified helper library

    main

    The src/helpers/index.js file serves as the primary entry point for the envinfo helper library. It aggregates various specialized modules into a single object, allowing you to access environment detection utilities for a wide range of technologies.

    By importing this module, you gain access to helpers for detecting:

    • System & Environment: system, utilities
    • Development Tools: binaries, browsers, databases, ides, languages, managers, monorepos, sdks
    • Infrastructure: servers, virtualization
    • Package Management: packages (via the packages module)

    This unified export pattern allows you to call detection functions directly from the main module without needing to know the internal directory structure.

    const envinfo = require('envinfo/src/helpers');
    
    // Example usage (actual function names depend on the specific sub-module exports)
    // const isNodeInstalled = envinfo.isNodeInstalled();
    // const getSystemInfo = envinfo.getSystemInfo();
  8. Reference: envinfo CLI options

    main

    Use the following flags to customize the scope and format of your environment report:

    Information Categories

    • --system: Print general system info such as OS, CPU, Memory and Shell
    • --browsers: Get version numbers of installed web browsers
    • --SDKs: Get platforms, build tools and SDKs of iOS and Android
    • --IDEs: Get version numbers of installed IDEs
    • --languages: Get version numbers of installed languages such as Java, Python, PHP, etc
    • --managers: Get version numbers of installed package/dependency managers
    • --monorepos: Get monorepo tools
    • --binaries: Get version numbers of node, npm, watchman, etc
    • --npmPackages: Get version numbers of locally installed npm packages - glob, string, or comma delimited list
    • --npmGlobalPackages: Get version numbers of globally installed npm packages
    • --pnpmGlobalPackages: Get version numbers of globally installed pnpm packages

    Dependency Tree Options

    • --duplicates: Mark duplicate npm packages inside parentheses eg. (2.1.4)
    • --fullTree: Traverse entire node_modules dependency tree, not just top level

    Output Formatting

    • --markdown: Print output in markdown format
    • --json: Print output in JSON format
    • --console: Print to console (defaults to on for CLI usage, off for programmatic usage)
    • --showNotFound: Don't filter out values marked 'Not Found'
    • --title <string>: Give your report a top level title ie 'Environment Report'
    # Example: Generate a JSON report of system info and local npm packages
    envinfo --system --npmPackages "@babel/*,lodash"
    
    # Example: Generate a Markdown report with a custom title
    envinfo --markdown --title "My Dev Environment"
  9. Reference the predefined environment presets

    main

    The envinfo project includes several predefined presets that group specific environment information categories (like System, Binaries, npmPackages, etc.) relevant to specific technologies or workflows. These presets can be used to quickly collect a tailored set of environment data.

    Available presets include:

    • defaults: A comprehensive set covering System, Binaries, Managers, Utilities, Servers, Virtualization, SDKs, IDEs, Languages, Databases, Browsers, and Monorepos.
    • cssnano: Focused on OS, CPU, Node-based binaries, and cssnano/postcss npm packages.
    • jest: Focused on OS, CPU, Node-based binaries, and jest npm packages.
    • react-native: Focused on OS, CPU, Node-based binaries, Watchman, SDKs, IDEs (Android Studio, Xcode, Visual Studio), and specific npm packages.
    • nyc: Focused on OS, CPU, Memory, Node-based binaries, and a glob pattern for Babel/Istanbul/NYC related packages.
    • webpack: Focused on OS, CPU, Node-based binaries, and webpack related npm/global packages.
    • styled-components: Focused on OS, CPU, Node-based binaries, Browsers, and styled-components npm packages.
    • create-react-app: Focused on OS, CPU, Node-based binaries, Browsers, and React-related npm/global packages.
    • apollo: Focused on OS, Node-based binaries, Browsers, and Apollo-related npm/global packages.
    • react-native-web: Focused on OS, CPU, Node-based binaries, Browsers, and React/React-Native-Web npm packages.
    • babel: Focused on OS, Node-based binaries, Monorepos, and a wide range of Babel/tooling related npm packages.
    • playwright: Focused on OS, CPU, Memory, Container, Node-based binaries, Bash, specific IDEs, and Playwright npm packages.