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
- Node.js
- Package.json
- Npm:Module - includes how to create an npm module
- Npm:Link -
npm link- mainly useful for library development. - GitLabCI:Npm - how to publish to npm from gitlab-ci, etc.
Tools
Scope
- scope | npm Docs
- How much do you know about NPM-SCOPE packages? - Dev. DY
- Stackoverflow - Why do some npm packages start with @?
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.
Creating a project
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.
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
Each is as follows:
- npm-run-all - runs multiple scripts sequentially/in parallel
- del-cli - removes files/directories
- delete-empty - removes empty directories
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:
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:
| |
Once the token is created, copy the token value into the ~/.npmrc file as follows.
Then publish again with npm publish ....
See also
Favorite site
- Managing npm dependency modules with package.json
- A Beginner's Guide to npm — the Node Package Manager 1
- Publishing my own NPM package (module)
- [Recommended] Openbase web site - review, check, and compare millions of open-source packages.
References
-
A_Beginners_Guide_to_npm_-_the_Node_Package_Manager.pdf ↩
- Berry
- Browserslist
- CodingGuidelines:TypeScript
- Continuous Integration
- ContinuousIntegration:ImplementationGuide
- Del-cli
- Delete-empty
- Electron-vue
- ESLint
- Font-files
- Fontsource
- GatsbyJS
- GitLab CI
- GitLab:PackageRegistry
- Gitlab:Webhook:Example
- GitLabCI:Npm
- Helm
- JavaScript:Libraries
- JupyterLab
- Kubernetes
- NodeJs:Native
- Nodenv
- Npm-run-all
- Npm:Link
- Npm:Module
- Npx
- Nrm
- Open Source
- Package management system
- Package.json
- Pnpm
- Programming
- RubyGems
- Software repository
- Syntactically Awesome Style Sheets
- Tbag
- TypeScript
- Vite:CreateLibraryProject
- Vls
- Volta
- Vue CLI Plugin Electron Builder
- Web development
- WebProgramming:Beginner
- Yarn