Creating and publishing scoped public packages
See Details
Table of contents
To share your code publicly in a user or organization namespace, you can publish public user-scoped or organization-scoped packages to the npm registry.
For more information on scopes, see "About scopes".
Note: Before you can publish user-scoped npm packages, you must sign up for an npm user account.
Additionally, to publish organization-scoped packages, you must create an npm user account, then create an npm organization.
Creating a scoped public package
-
If you are using npmrc to manage accounts on multiple registries, on the command line, switch to the appropriate profile:
npmrc <profile-name> -
On the command line, create a directory for your package:
mkdir my-test-package -
Navigate to the root directory of your package:
cd my-test-package -
If you are using git to manage your package code, in the package root directory, run the following commands, replacing
git-remote-urlwith the git remote URL for your package:git initgit remote add origin git://git-remote-url -
In the package root directory, run the
npm initcommand and pass the scope to thescopeflag:-
For an organization-scoped package, replace
my-orgwith the name of your organization:npm init --scope=@my-org -
For a user-scoped package, replace
my-usernamewith your username:npm init --scope=@my-username
-
-
Respond to the prompts to generate a
package.jsonfile. For help naming your package, see "Package name guidelines". -
Create a README file that explains what your package code is and how to use it.
-
In your preferred text editor, write the code for your package.
Reviewing package contents for sensitive or unnecessary information
Publishing sensitive information to the registry can harm your users, compromise your development infrastructure, be expensive to fix, and put you at risk of legal action. We strongly recommend removing sensitive information, such as private keys, passwords, personally identifiable information (PII), and credit card data before publishing your package to the registry.
For less sensitive information, such as testing data, use a .npmignore or .gitignore file to prevent publishing to the registry. For more information, see this article.