explaingit

istanbuljs/nyc

5,762JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

nyc is the command-line interface for Istanbul, a JavaScript code coverage tool that tracks which lines of code run during tests. Wrap your test command with nyc to get instant coverage reports, enforce minimum thresholds, and export results in formats like lcov and HTML for CI integration.

Mindmap

mindmap
  root((nyc))
    Coverage Tracking
      Line counters
      All files flag
      Child processes
    Test Frameworks
      Mocha
      TAP
      AVA
    Report Formats
      Terminal table
      lcov
      HTML
    Configuration
      CLI flags
      Config file
      package.json section
    File Filtering
      Include globs
      Exclude globs
    Language Support
      TypeScript preset
      Babel preset
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Measure test coverage on a JavaScript project by wrapping your test command with nyc to see which lines are untested.

USE CASE 2

Enforce minimum coverage thresholds in CI so test quality cannot silently degrade over time.

USE CASE 3

Generate lcov or HTML coverage reports for upload to services like Codecov or Coveralls.

USE CASE 4

Track coverage across TypeScript or Babel projects using built-in preset support.

Tech stack

JavaScriptNode.jsIstanbullcovMochaTAPAVABabel

Getting it running

Difficulty · easy Time to first run · 5min

Install with npm install --save-dev nyc, then prefix your test script in package.json with nyc (e.g. nyc mocha). No other config needed to get a basic terminal coverage report.

ISC license, a permissive open-source license similar to MIT. You can use, modify, and distribute freely with minimal restrictions.

In plain English

nyc is the command-line tool for Istanbul, a JavaScript code coverage library. Code coverage tells you which lines of your code actually ran during your tests, and which lines were never touched. This is useful for spotting parts of your code that your tests do not exercise, and for setting minimum thresholds to ensure test quality does not slip over time. To use nyc, you wrap your existing test command with it. If you normally run your tests with mocha, you would instead run nyc mocha, and nyc will automatically track which lines ran and generate a report when the tests finish. It works with most JavaScript test frameworks including mocha, tap, and AVA. If you use jest or tap, those tools already include Istanbul's coverage engine and you would configure coverage through them directly rather than through nyc. The tool instruments your JavaScript files by inserting counters into the code before running it. By default it only tracks files that actually get loaded during the test run, but you can turn on an --all flag to include every file in the project in the report, even ones no test touched. You can include or exclude specific files and folders using glob patterns. Reports can be output in several formats. The default prints a summary table in the terminal. Other formats include lcov (a widely supported format that most CI tools and code coverage services can consume) and HTML (which produces a browsable page showing which lines are covered). Multiple formats can be requested at once. Configuration can be done through command-line flags, through a dedicated config file in JSON or YAML format, or through a nyc section in package.json. There is preset support for TypeScript and Babel projects. nyc also handles projects that spawn child processes during tests, tracking coverage across all spawned processes.

Copy-paste prompts

Prompt 1
I have a Node.js project using Mocha. Show me how to add nyc for code coverage, configure a minimum branch coverage threshold of 80%, and output both a terminal summary and an lcov report.
Prompt 2
Using nyc with a Babel project, write the nyc config section I need in package.json to instrument transpiled files correctly and exclude the test folder from coverage.
Prompt 3
I want nyc to report coverage for every file in my project, not just files loaded during tests. Show me the command and config option to enable this, and explain what the output table columns mean.
Prompt 4
My nyc coverage report is missing some files. Walk me through using include and exclude glob patterns in the nyc config to control exactly which files appear in the report.
Prompt 5
Show me how to integrate nyc into a GitHub Actions CI workflow that fails the build if coverage drops below 90% and uploads the lcov report to Codecov.
Open on GitHub → Explain another repo

← istanbuljs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.