github/gitignore · Node.gitignore
Node.js .gitignore 템플릿 해설
Node.gitignore가 node_modules, 로그, 빌드 산출물, .env, 각종 도구 캐시를 왜 무시하는지 규칙별로 설명하고 lockfile·Yarn Berry 주의점을 정리합니다.
Node.gitignore는 npm·Yarn·pnpm으로 의존성을 설치하는 JavaScript/TypeScript 프로젝트용 템플릿이다. 특정 프레임워크 하나가 아니라 Next.js, Nuxt, Gatsby, SvelteKit, VitePress, Docusaurus, Serverless 같은 생태계 도구가 만드는 캐시·빌드 폴더를 폭넓게 모아 두었다.
핵심은 세 가지다. 설치하면 다시 생기는 의존성(node_modules/), 실행 중에 생기는 로그·런타임 파일, 그리고 커밋하면 곤란한 환경 변수 파일(.env)이다. 반대로 package.json과 lockfile은 이 템플릿이 무시하지 않으며, 커밋해야 하는 파일이다.
규칙별 해설
| 패턴 | 무엇을, 왜 무시하나 |
|---|---|
node_modules/jspm_packages/web_modules/bower_components | 의존성 디렉터리npm install로 언제든 다시 만들 수 있고 파일 수가 수만 개에 이르며, 운영체제별 네이티브 바이너리가 섞여 있어 다른 환경에서 그대로 쓰면 오히려 깨진다. 슬래시 없는 패턴이라 모노레포의 하위 패키지에 있는 node_modules도 함께 걸린다. |
logs*.lognpm-debug.log*yarn-debug.log*yarn-error.log*report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | 로그와 진단 리포트패키지 매니저가 실패할 때 남기는 디버그 로그와 Node.js 진단 리포트(process.report)다. 실행한 사람의 환경과 경로가 담기고, 매번 새로 생기므로 이력에 남길 이유가 없다. |
pids*.pid*.pid.lockcoverage*.lcov.nyc_outputlib-cov | 런타임·커버리지 산출물프로세스 ID 파일과 테스트 커버리지 결과다. 커버리지는 CI에서 매번 새로 계산하는 값이므로 저장소에 두면 충돌만 늘어난다. |
distout.next.nuxt.output.svelte-kit/build/Release*.tsbuildinfo | 빌드 결과번들러와 프레임워크가 만든 결과물이다. *.tsbuildinfo는 TypeScript 증분 빌드 정보다. dist·out처럼 끝에 /가 없는 패턴은 같은 이름의 파일도 무시하므로, 소스에 그런 이름의 파일이 있다면 규칙을 /dist/처럼 좁혀야 한다. |
.env.env.*!.env.example | 환경 변수 파일API 키·DB 비밀번호가 들어가는 파일이다. .env.local, .env.production 같은 변형도 .env.*로 막고, 값 없이 키 목록만 적은 .env.example은 !로 다시 포함해 팀원이 어떤 변수가 필요한지 알 수 있게 했다. |
.npm.eslintcache.stylelintcache.cache.parcel-cache.vite/.pnpm-store | 도구 캐시린터·번들러·패키지 매니저가 속도를 위해 쓰는 캐시다. 지워도 자동으로 다시 만들어지며, 사람마다 내용이 달라 커밋하면 불필요한 변경이 계속 생긴다. |
.pnp.*.yarn/*!.yarn/patches!.yarn/plugins!.yarn/releases!.yarn/sdks!.yarn/versions | Yarn Berry(2+).yarn/ 안의 내용만 제외(.yarn/*)하고 공유가 필요한 하위 폴더를 !로 되살리는 구조다. .yarn/로 디렉터리 자체를 제외했다면 git이 그 안을 보지 않아 ! 규칙이 먹지 않는다. |
실무에서 주의할 점
package-lock.json,yarn.lock,pnpm-lock.yaml은 무시하지 말고 커밋한다. npm 문서도 lockfile을 소스 관리에 넣을 것을 강하게 권한다.- Yarn의 Zero-Installs(
.yarn/cache를 커밋하는 방식)를 쓴다면.pnp.*규칙을 지우고!.yarn/cache를 추가해야 한다. .env를 이미 커밋했다면 무시 규칙만으로는 사라지지 않는다.git rm --cached .env로 추적을 끊고, 노출된 키는 폐기·재발급한다.- macOS의
.DS_Store나 에디터 설정은 이 템플릿에 없으므로 macOS·VisualStudioCode 템플릿을 함께 고르거나 전역 gitignore에 둔다.
원본 템플릿
Node.gitignore
# 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/
템플릿 출처: github/gitignore/Node.gitignore @356fd7b (2026-09-11) · CC0-1.0