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"
  }
}

Troubleshooting

Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages

다음과 같이 배포하면:

npm publish ...

다음 에러가 출력된다:

npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access
npm error code E403
npm error 403 403 Forbidden - PUT https://registry.npmjs.org/@cvprun%2fcli - Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages.
npm error 403 In most cases, you or one of your dependencies are requesting
npm error 403 a package version that is forbidden by your security policy, or
npm error 403 on a server you do not have access to.
npm error A complete log of this run can be found in: /home/zer0/.npm/_logs/2026-08-07T04_54_52_052Z-debug-0.log

요약하면

패키지를 게시하려면 2단계 인증 또는 2단계 인증 우회 기능이 활성화된 세부 액세스 토큰이 필요합니다.
Npm-new_granular_access_token-bypass_2fa.png

토큰이 등록되면 ~/.npmrc 파일에 다음과 같이 토큰 값을 복사하면 된다.

//registry.npmjs.org/:_authToken=npm_XXXXXXXXXX

이 후 다시 npm publish ... 으로 배포하면 된다.

See also

Favorite site

References


  1. A_Beginners_Guide_to_npm_-_the_Node_Package_Manager.pdf