Skip to content
Search

Npm

lastmod 2026-08-07created 2015-11-2940 edits

npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command-line client and an online database of public packages and paid private packages.

Categories

Tools

Scope

You may see packages with @ in the module name. All such packages are scoped packages.

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

Creating a project

npm init

Module Debugging

Use npm link. Run in a package folder, it creates a symbolic link in the global folder that points to the package where the command was run.

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/.
  • At Username, enter your user ID,
  • At Password, enter your password,
  • At Email, enter your registered email, (then check your email to get the OPT)
  • At one-time password, enter the OPT from above.

Publish

First log in, set private: false in the package.json file, and run the following command.

npm publish --access=public

Note that without --access=public at the end, the following warning telling you to pay is printed:

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

Each is as follows:

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

Publishing like this:

npm publish ...

prints the following error:

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

In short:

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

Once the token is created, copy the token value into the ~/.npmrc file as follows.

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

Then publish again with npm publish ....

See also

Favorite site

References


  1. A_Beginners_Guide_to_npm_-_the_Node_Package_Manager.pdf ↩

author Zer0 sitemap