github/gitignore · Node.gitignore

Node.js .gitignore Template Explained

A rule-by-rule explanation of why Node.gitignore ignores node_modules, logs, build output, .env and tool caches, plus notes on lockfiles and Yarn Berry.

Open in generator Open with macOS, VisualStudioCode, Nextjs, JetBrains

Node.gitignore is the template for JavaScript/TypeScript projects that install dependencies with npm, Yarn or pnpm. Rather than targeting a single framework, it collects the cache and build folders created by ecosystem tools such as Next.js, Nuxt, Gatsby, SvelteKit, VitePress, Docusaurus and Serverless.

It covers three main things: dependencies that come back when you reinstall (node_modules/), logs and runtime files created while running, and environment variable files that should not be committed (.env). On the other hand, the template does not ignore package.json or lockfiles; those are files you should commit.

Rules explained

PatternWhat it ignores and why
node_modules/jspm_packages/web_modules/bower_componentsDependency directoriesThey can be recreated at any time with npm install, can contain tens of thousands of files, and include OS-specific native binaries that break when used as-is on another machine. Because the pattern has no slash, it also matches node_modules inside sub-packages of a monorepo.
logs*.lognpm-debug.log*yarn-debug.log*yarn-error.log*report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.jsonLogs and diagnostic reportsDebug logs left by a failing package manager and Node.js diagnostic reports (process.report). They contain the environment and paths of whoever ran the command and are regenerated every time, so there is no reason to keep them in history.
pids*.pid*.pid.lockcoverage*.lcov.nyc_outputlib-covRuntime and coverage outputProcess ID files and test coverage results. Coverage is recalculated on every CI run, so keeping it in the repository only adds conflicts.
distout.next.nuxt.output.svelte-kit/build/Release*.tsbuildinfoBuild outputOutput produced by bundlers and frameworks. *.tsbuildinfo holds TypeScript incremental build information. Patterns without a trailing /, such as dist and out, also ignore files with the same name, so if your source has such a file, narrow the rule to something like /dist/.
.env.env.*!.env.exampleEnvironment variable filesFiles that hold API keys and database passwords. Variants such as .env.local and .env.production are blocked with .env.*, while .env.example, which lists only the keys without values, is re-included with ! so teammates can see which variables are needed.
.npm.eslintcache.stylelintcache.cache.parcel-cache.vite/.pnpm-storeTool cachesCaches that linters, bundlers and package managers use for speed. They are recreated automatically when deleted, and their contents differ from person to person, so committing them produces a constant stream of unnecessary changes.
.pnp.*.yarn/*!.yarn/patches!.yarn/plugins!.yarn/releases!.yarn/sdks!.yarn/versionsYarn Berry (2+)This structure excludes only the contents of .yarn/ (.yarn/*) and restores the subfolders that need to be shared with !. If you excluded the directory itself with .yarn/, git would not look inside it and the ! rules would have no effect.

Practical notes

Original template

Node.gitignore63 rules
# Logslogs*.lognpm-debug.log*yarn-debug.log*yarn-error.log*lerna-debug.log*# Diagnostic reports (https://nodejs.org/api/report.html)report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json# Runtime datapids*.pid*.seed*.pid.lock# Directory for instrumented libs generated by jscoverage/JSCoverlib-cov# Coverage directory used by tools like istanbulcoverage*.lcov# nyc test coverage.nyc_output# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files).grunt# Bower dependency directory (https://bower.io/)bower_components# node-waf configuration.lock-wscript# Compiled binary addons (https://nodejs.org/api/addons.html)build/Release# Dependency directoriesnode_modules/jspm_packages/# Snowpack dependency directory (https://snowpack.dev/)web_modules/# TypeScript cache*.tsbuildinfo# Optional npm cache directory.npm# Optional eslint cache.eslintcache# Optional stylelint cache.stylelintcache# Optional REPL history.node_repl_history# Output of 'npm pack'*.tgz# Yarn Integrity file.yarn-integrity# dotenv environment variable files.env.env.*!.env.example# parcel-bundler cache (https://parceljs.org/).cache.parcel-cache# Next.js build output.nextout# Nuxt.js build / generate output.nuxtdist.output# Gatsby files.cache/# Comment in the public line in if your project uses Gatsby and not Next.js# https://nextjs.org/blog/next-9-1#public-directory-support# public# vuepress build output.vuepress/dist# vuepress v2.x temp directory.temp# Sveltekit cache directory.svelte-kit/# vitepress build output**/.vitepress/dist# vitepress cache directory**/.vitepress/cache# Docusaurus cache and generated files.docusaurus# Serverless directories.serverless/# FuseBox cache.fusebox/# DynamoDB Local files.dynamodb/# Firebase cache directory.firebase/# TernJS port file.tern-port# Stores Visual Studio Code versions used for testing Visual Studio Code extensions.vscode-test# pnpm.pnpm-store# yarn v3.pnp.*.yarn/*!.yarn/patches!.yarn/plugins!.yarn/releases!.yarn/sdks!.yarn/versions# Vite filesvite.config.js.timestamp-*vite.config.ts.timestamp-*.vite/

Templates from github/gitignore/Node.gitignore @356fd7b (2026-09-11) · CC0-1.0

Often used together

More template explanations