JavaScript .gitignore template
The JavaScript template ignores installed dependencies, process id files and the caches that package managers and linters scatter through the working tree.
At a glance
- Category
- Language
- Patterns in this template
- 12 rules
- Directories ignored
- 5 of the 12 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Nothing in this template matches .DS_Store, Thumbs.db or editor swap files.
- Typical companions
- npm, Yarn or pnpm for the lockfile rules, plus an OS and an editor template.
In detail
node_modules is the installed copy of every direct and transitive dependency. It is not source: the package manager rebuilds it from your manifest and lockfile, and on any project of size it runs to tens of thousands of files. Committing it makes every diff unreadable, and packages that ship compiled native binaries will simply be wrong for anyone on a different operating system or processor.
The instinct that trips people up is that the file sitting right next to node_modules works the opposite way. The lockfile is the thing you must commit. It is what pins the exact resolved versions, so without it the reinstall this template assumes is possible produces a different dependency tree on every machine and in CI.
jspm_packages and bower_components are the same idea from two earlier package managers. Most projects will never create either directory, and the rules cost nothing while quietly covering an old repository that still does. lib-cov is a coverage output folder from the same era.
The remaining rules are runtime debris. Files ending in .pid and .pid.lock, plus the pids directory, are written by process supervisors recording which process id is currently running. Files ending in .seed come from old random seed dumps. Those are per machine and per run, and a committed one is stale the moment it lands.
The last group is caches and history stored inside the tree: .npm, .eslintcache, .yarn-integrity and .node_repl_history. That last one is worth pausing on, because it records everything typed at the interactive prompt, which for a lot of people includes a connection string or a token pasted in while debugging.
Examples
node_modules/
jspm_packages/
bower_components/
*.seed
*.pid
*.pid.lock
lib-cov/
pids/
.npm
.eslintcache
.node_repl_history
.yarn-integrity12 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- This template does not ignore .npmrc, and a project-local .npmrc is exactly where a registry auth token ends up. Add it yourself, or keep the token in the user-level file in your home directory instead.
- node_modules/ has no leading slash, so it matches at every depth. In a monorepo that is what you want, but people who expect it to apply only at the repository root are sometimes surprised that a nested package directory is covered too.
- The trailing slash means the rule matches a directory only. That is almost always correct here, and it is also why the rule quietly does nothing if a build step ever emits a plain file with the same name.
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 →TypeScript .gitignore template
The TypeScript template ignores compiled output, source maps and build info, but its *.d.ts rule is broader than most projects want. Here is each line.
Node.js .gitignore template
The longest JavaScript oriented template: dependency directories, every package manager's debug log, bundler caches, env files and Yarn Plug'n'Play state.
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.
Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
Java .gitignore template
What the Java .gitignore template ignores: compiled classes, packaged archives, crash dumps, and the negations that keep the Gradle wrapper jar tracked.
Go .gitignore template
The Go template ignores platform binaries by extension, which misses the extensionless binary go build produces on Linux and macOS. Here is what to add.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- package.json Generator Generate package.json files with a form-based builder - 8 project presets, all fields supported