Skip to content

Npm

npm은 자바스크립트 프로그래밍 언어를 위한 패키지 관리자이다. 자바스크립트 런타임 환경 Node.js의 기본 패키지 관리자이다. 명령 줄 클라이언트, 그리고 공개 패키지와 지불 방식의 개인 패키지의 온라인 데이터베이스로 이루어져 있다.

Categories

Tools

Scope

모듈 이름에 @ 가 붙은 패키지를 볼 수 있을 것이다. 이러한 패키지가 모두 범위가 있는 패키지이다.

How to Initialize a Scoped Package

To create a scoped package, you simply use a package name that starts with your scope.

{
  "name": "@username/project-name"
}

프로젝트 만들기

npm init

Module Debugging

npm link를 사용하라. 패키지 폴더에서 명령이 실행된 패키지로 연결되는 전역 폴더에 심볼릭 링크를 만듭니다.

Login

$ npm login
npm notice Log in on https://registry.npmjs.org/
Username: yourid
Password:
Email: (this IS public) [email protected]
npm notice Please check your email for a one-time password (OTP)
Enter one-time password: 87623307
Logged in as yourid on https://registry.npmjs.org/.
  • Username 에서 사용자 아이디 입력,
  • Password 에서 비밀번호 입력,
  • Email 에서 등록한 나의 이메일을 입력, (이후, 이메일을 확인하면 OPT를 알아낼 수 있다)
  • one-time password 에서 위의 OPT 를 입력하면 된다.

Publish

우선 로그인하고, package.json 파일에 private: false로 돌리고, 다음 명령을 날린다.

npm publish --access=public

참고로 뒤에 --access=public를 안붙이면 다음과 같이 돈내라는 경고가 출력된다:

npm ERR! code E402
npm ERR! 402 Payment Required - PUT http://registry.npmjs.org/@sub0709%2fjson-config - You must sign up for private packages

Scripts

Calean, Multiple Run, ETC

$ npm i -D npm-run-all del-cli delete-empty

각각 다음과 같다:

These three packages, will, in order, let you run NPM scripts sequentially or in parallel from other npm scripts, let you delete items, and let you delete empty folders. These three combine to make a few really handy scripts possible:

{
  "scripts": {
    "prestart": "run-s clean",
    "start": "run-p *:dev",
    "prebuild": "run-s clean",
    "build": "NODE_ENV=production run-s eleventy:build vite:build",
    "clean": "run-s clean:files clean:empty",
    "clean:files": "del 'src/**/*.html' public",
    "clean:empty": "delete-empty src",
    "eleventy:dev": "eleventy --watch",
    "eleventy:build": "eleventy",
    "vite:dev": "vite",
    "vite:build": "vite build"
  }
}

See also

Favorite site

References


  1. A_Beginners_Guide_to_npm_-_the_Node_Package_Manager.pdf