본문으로 건너뛰기
🛠️ToolsShed

npm / yarn / pnpm 명령어 레퍼런스

npm, yarn, pnpm 패키지 매니저 명령어 빠른 참조.

명령어 (npm)설명
npm initInitialize a new project with a package.json file
npm init -yInitialize with defaults (skip prompts)
npm installInstall all dependencies from package.json
npm ciClean install from lockfile (CI environments)
npm lsList installed packages
npm outdatedCheck for outdated packages
npm install <pkg>Install and add to dependencies
npm install -D <pkg>Install and add to devDependencies
npm install -g <pkg>Install package globally
npm uninstall <pkg>Remove a package
npm update <pkg>Update a specific package
npm updateUpdate all packages to latest allowed versions
npm auditRun a security audit
npm audit fixAutomatically fix vulnerabilities
npm dedupeReduce duplication in node_modules
npm cache clean --forceClear the package cache
npm run <script>Run a script defined in package.json
npm startRun the 'start' script
npm testRun the 'test' script
npm run buildRun the 'build' script
npx <cmd>Execute a package binary without installing
npm loginLog in to npm registry
npm publishPublish package to the registry
npm version <type>Bump version (patch/minor/major)
npm packCreate a tarball of the package
npm deprecateDeprecate a published version

이 도구 소개

npm, yarn, pnpm은 자바스크립트에서 가장 널리 사용하는 패키지 관리자이며, 각각 고유한 명령 구문과 특징을 가지고 있습니다. 서로 다른 프로젝트를 오가며 작업하는 개발자는 이들을 자주 바꿔 가며 쓰는데, 명확한 레퍼런스 없이 특정 작업에 필요한 정확한 명령을 기억하기란 답답할 수 있습니다.

이 레퍼런스는 세 관리자 모두에서 패키지를 설치, 업데이트, 제거, 나열할 때 가장 자주 쓰는 명령어를 모아 두었으므로, 공식 문서를 매번 참조하지 않고도 알맞은 명령어를 찾을 수 있습니다. 개발 종속성 설치, 커스텀 스크립트 실행, 전역 패키지 나열, 빌드 문제 해결 전 캐시 삭제 등을 확인할 때 활용할 수 있습니다.

각 명령어는 npm, yarn, pnpm 간에 나란히 표시되므로 도구를 바꿀 때 워크플로를 빠르게 적응시킬 수 있습니다. 새 프로젝트를 시작하든, 워크스페이스 종속성을 관리하든, 빠진 패키지를 디버깅하든, 이 페이지는 구문을 처음부터 정확하게 입력하도록 도와줍니다.

자주 묻는 질문

코드 구현

# Run npm/shell commands from Python
import subprocess
import json
import os

def npm_install(package, dev=False):
    """Install an npm package"""
    cmd = ['npm', 'install']
    if dev:
        cmd.append('--save-dev')
    cmd.append(package)
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.returncode == 0

def get_package_json():
    """Read package.json"""
    with open('package.json') as f:
        return json.load(f)

def npm_run(script):
    """Run an npm script"""
    result = subprocess.run(
        ['npm', 'run', script],
        capture_output=True, text=True
    )
    print(result.stdout)
    if result.returncode != 0:
        print(result.stderr)
    return result.returncode == 0

# Example usage
npm_install('lodash')
npm_install('typescript', dev=True)
npm_run('build')

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.