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

매일 치는 npm 명령

~13 min · npm, commands, workflow, ci

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

매일 작업 carry 하는 명령은 npm 의 전체 surface 보다 작음. 6개가 칠 거 대부분 커버.

npm init 가 프로젝트 생성 (또는 npm init -y 로 prompt 건너뛰고 디폴트 수락). args 없는 npm installpackage.json 에 나열된 모든 의존성 install; 패키지 이름과 함께면 그 패키지 추가. -D flag 가 dev 의존성 표시 (빌드 도구, test runner) — production deps 가 디폴트.

npm ci 가 CI/CD install. node_modules 삭제, package-lock.json 정확히 읽음, lockfile 이 package.json 과 sync 안 맞으면 실패, strict 하게 install. npm install 보다 빠르고 strict — 자동 빌드 일어나는 모든 곳에 사용.

npm run <script> 가 package.json 의 scripts 섹션에 정의된 스크립트 실행. npm testnpm start 는 shortcut (no run); 나머지 다 npm run 필요.

npx <tool> 가 install 없이 패키지 다운 + 실행. 일회용 도구에 사용 (npx create-react-app, npx tsc --init) 그러면 글로벌 install set 안 오염.

npm audit 가 의존성 트리에서 알려진 취약점 스캔. 매주 돌려. npm audit fix 가 비파괴 fix 적용; commit 전 출력 검토.

Code

init, install, add, remove·bash
# 새 프로젝트
npm init -y

# package.json 의 모든 거 install
npm install

# 런타임 dep 추가
npm install express

# dev dep 추가
npm install -D vitest typescript

# 제거
npm uninstall express
CI install — strict, fast, lockfile-respecting·bash
# CI 스크립트에서 (GitHub Actions, GitLab CI, ...)
npm ci

# 'npm install' 과 차이:
# - node_modules 먼저 삭제
# - package-lock.json 에서 strict install (resolution 안 함)
# - package.json 과 lockfile 이 disagree 면 실패
# - 더 빠름 (resolution 작업 없음) 재현 가능
Scripts + npx·bash
# package.json 의 "scripts" 에 정의됨
npm run build
npm run dev
npm test          # shortcut, 'run' 불필요
npm start         # shortcut, 'run' 불필요

# 글로벌 install 오염 없이 일회용 도구
npx create-vite my-app
npx tsc --init
npx eslint .
보안 + 정비·bash
# 취약점 찾기
npm audit

# 비파괴 fix 적용 (commit 전 검토!)
npm audit fix

# 뭐가 outdated?
npm outdated

# 인터랙티브 업그레이드 (새 npm 버전)
npm update

External links

Exercise

기존 JS 프로젝트에서 'npm audit' 돌리고 보고서 읽어. 뭔가 flag 됐으면 'npm audit fix' 돌리고 commit 전 lockfile diff 검토. 그 다음 CI 설정 (GitHub Actions 등) 봐 — 'npm install' 쓰나 'npm ci' 쓰나? 'npm ci' 로 안 쓰면 바꿔.

Progress

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

댓글 0

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

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