Node.js .gitignore template
The Node.js template is the broad one, covering dependencies, debug logs from four package managers, bundler caches, environment files and the newer Yarn state directories.
At a glance
- Category
- Framework
- Patterns in this template
- 46 rules
- Directories ignored
- 14 of the 46 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. This template is comprehensive about tooling and silent about the operating system.
- Typical companions
- A framework template if you use one, plus an OS template and an editor template.
In detail
This is the template people reach for when they want coverage rather than precision. It carries node_modules twice, which is harmless, and adds jspm_packages, bower_components and web_modules for repositories that predate the current tooling. The reasoning is the same as always: the dependency tree is restored from the lockfile, and the lockfile is the file you commit.
The log rules are unusually thorough because each package manager names its crash log differently: npm-debug.log, yarn-debug.log, yarn-error.log, lerna-debug.log and pnpm-debug.log, all with a trailing wildcard to catch the numbered variants. The report.*.json pattern catches the diagnostic report the runtime writes when it hits an unrecoverable error, which includes the full environment and command line.
The environment rules cover .env, .env.test and .env.production. Notably they do not cover .env.local or .env.development, so a project using those names needs to add them. This is the most common gap people hit with this template, and it is easy to miss because the file that gets committed is usually the one that was named slightly differently.
The cache rules span bundlers and linters: .cache, .parcel-cache, .npm, .eslintcache, .stylelintcache, .nyc_output and coverage. The .serverless, .fusebox and .dynamodb entries cover deployment and local emulation tooling. .tern-port holds the port number of a running editor language server, which is a good illustration of how much local runtime state ends up in a project root.
The Yarn block is the newest addition and the one that trips people up. .yarn/cache, .yarn/unplugged, .yarn/build-state.yml and .yarn/install-state.gz are ignored, along with .pnp.*. Whether that is correct depends on which install mode you use, because the zero install workflow deliberately commits the cache so a clone needs no network at all.
Examples
node_modules/
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
pnpm-debug.log*
.pnpm-store/
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
pids/
*.pid
*.seed
*.pid.lock
lib-cov/
coverage/
.nyc_output/
.grunt
bower_components/
.lock-wscript
build/Release
node_modules/
jspm_packages/
web_modules/
*.tgz
.yarn-integrity
.env
.env.test
.env.production
.cache
.parcel-cache
.npm
.eslintcache
.stylelintcache
.node_repl_history
*.tsbuildinfo
.serverless/
.fusebox/
.dynamodb/
.tern-port
.vscode-test
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*46 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- The environment rules cover .env.production and .env.test but not .env.local. If your project uses that name, add it, because none of the existing rules will catch it.
- If you use the zero install workflow, ignoring .yarn/cache defeats the entire point of it. Remove that line and the .pnp.* line, and keep the rest.
- .node_repl_history is included for a reason: it records everything typed at the interactive prompt, which routinely includes a pasted connection string.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →JavaScript .gitignore template
Every rule in the JavaScript .gitignore template explained: why node_modules is restored rather than committed, and what the old package folders catch.
npm .gitignore template
This template ignores package-lock.json, which contradicts the current advice to commit the lockfile. Here is what the rest of it covers and what to change.
Yarn .gitignore template
The Yarn template ignores the .yarn directory's contents while negating five subdirectories, because which ones you keep depends on the install mode you use.
React .gitignore template
A short template built around one idea: the .env.local family is per developer and never committed, while the plain .env is shared and usually should be.
Next.js .gitignore template
What the Next.js template ignores: the build cache, the static export folder, deployment state, and one wildcard that covers every local environment file.
Vue .gitignore template
The Vue template ignores build output and local environment files, and is one of the few that also carries operating system and editor rules of its own.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- .env Editor & Validator Edit and validate .env files online - detect duplicates, mask secrets, generate .env.example
- package.json Generator Generate package.json files with a form-based builder - 8 project presets, all fields supported