도움되는 npm 명령어들

less than 1 minute read

npm

npm은 여러 커맨드들을 지원하고 있습니다. 그 중 유용하다고 생각되는 명령어를 소개하겠습니다.

audit

audit은 package.json에 설치된 npm package들의 security 이슈들을 확인하고 reporting 해준다.

$ npm audit
    === npm audit security report ===

found 0 vulnerabilities
 in 21397 scanned packages

만약 어떤 모듈에 이슈가 있다면 npm audit fix를 통해 수정이 가능하다.

$ npm audit fix
npm WARN acorn-jsx@5.0.1 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.

up to date in 7.154s
fixed 0 of 0 vulnerabilities in 21397 scanned packages

이 명령어를 CI / CD 파이프라인에 넣어두면 최근 발생한 event-stream 이슈를 처리하는데 도움이 될 터이다.

prune

prune은 프로젝트와 관련 없는 npm package를 제거 할 때 사용한다.

$ npm prune

특히 production 옵션은 proudction 배포를 위한 package만 남기는데 유용하다.(특히 도커 이미지 빌드에 유용하다)

Test 후 실행은 npm install=> npm test => npm prune --production => npm start 순으로 할 수 있다.

$ npm prune

rebuild

rebuild는 npm package들을 rebuild하는 커맨드이다. 특정 pacakge들은 os 환경에 dependent 하다.

gcc 컴파일이 필요한 package들이 그렇다.

예를 들어 ubuntu에서 build한 프로젝트들을 node_modules 까지 그대로 복사해서 alpine에서 실행하려 한다면, rebuild 이후에 사용하는게 정신 건강에 이롭다.

$ npm rebuild

Categories: ,

Updated: