Npm
npm은 자바스크립트 프로그래밍 언어를 위한 패키지 관리자이다. 자바스크립트 런타임 환경 Node.js의 기본 패키지 관리자이다. 명령 줄 클라이언트, 그리고 공개 패키지와 지불 방식의 개인 패키지의 온라인 데이터베이스로 이루어져 있다.
Categories
- Node.js
- Package.json
- Npm:Module - npm 모듈 만드는 방법 포함
- Npm:Link -
npm link- 주로 라이브러리 개발에 유용하게 사용된다. - GitLabCI:Npm - gitlab-ci에서 npm 배포 방법 등
Tools
Scope
- scope | npm Docs
- NPM-SCOPE 패키지 어디까지 알고 있니? - Dev. DY
- Stackoverflow - Why do some npm packages start with @?
모듈 이름에 @ 가 붙은 패키지를 볼 수 있을 것이다. 이러한 패키지가 모두 범위가 있는 패키지이다.
How to Initialize a Scoped Package
To create a scoped package, you simply use a package name that starts with your scope.
프로젝트 만들기
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로 돌리고, 다음 명령을 날린다.
참고로 뒤에 --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-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 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
요약하면
| |
토큰이 등록되면 ~/.npmrc 파일에 다음과 같이 토큰 값을 복사하면 된다.
이 후 다시 npm publish ... 으로 배포하면 된다.
See also
Favorite site
- package.json으로 npm 의존성 모듈 관리하기
- A Beginner's Guide to npm — the Node Package Manager 1
- 내 NPM 패키지(모듈) 배포하기
- [추천] Openbase web site - 수백만 개의 오픈 소스 패키지를 리뷰, 확인, 비교.
References
-
A_Beginners_Guide_to_npm_-_the_Node_Package_Manager.pdf ↩