C.W.K.
Stream
Lesson 05 of 05 · published

npm Wisdom

~10 min · npm, wisdom, production

Level 0초심자
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

npm 은 forgiving — 그래서 대부분 팀이 자기도 모르게 나쁜 습관 들임. 이 룰들이 install '그냥 됨' 팀과 격주 월요일 install 이슈 디버깅하는 팀 가름.

항상 package-lock.json commit. 팀원이 너랑 다른 lockfile 가지면 다른 버그 가짐. lockfile 이 install — commit.

모든 CI/CD 파이프라인에서 npm ci 사용. npm install 은 더 나은 resolution 찾을 때 lockfile 업데이트; CI 에서 잘못된 동작, install 은 deterministic 해야 함.

npm audit 정기적으로. critical 취약점에 fail 하는 매주 cron 또는 CI job 추가. npm 에 대한 supply-chain 공격 진짜고 커지는 위험.

일회용 도구엔 npx 사용. 글로벌 install 패키지는 정비 부담; npx create-react-app 한 번 작동하고 흔적 안 남김.

라이브러리는 deps 핀, 앱은 range. 라이브러리 ship 하면 정확한 버전 핀해서 consumer 안 깨뜨림. 앱 ship 하면 range 해서 보안 패치 흘러들어감.

production 에 dev deps ship 안 함. production Docker 빌드의 npm install --omit=dev 가 이미지 크기 작게 + 공격 surface 감소.

Code

Production 만 install·bash
# Dockerfile 또는 production install 스크립트에서
npm ci --omit=dev

# 또는 옛 npm 버전
npm install --production
GitHub Actions: canonical npm CI 단계·yaml
# .github/workflows/ci.yml
name: ci
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: 'npm'
      - run: npm ci          # NOT npm install
      - run: npm test
      - run: npm audit --audit-level=high

External links

Exercise

프로젝트 하나를 이 wisdom 들에 맞게 audit: (1) package-lock.json commit 됐나? (2) CI 가 'npm ci' 쓰나? (3) 마지막 'npm audit' 언제? (4) production 에 devDeps 깔려있나? 'npm hygiene' 제목의 single PR 에서 갭 다 fix.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.