1 ---
2 title: Creating and publishing private packages
3 redirect_from:
4 - /private-modules/intro
5 ---
6
7 import shared from '~/shared.js'
8
9 To share your code with a limited set of users or teams, you can publish private user-scoped or organization-scoped packages to the npm registry.
10
11 For more information on scopes and private packages, see "[About scopes][scopes]" and "[About private packages][private-pkgs]".
12
13 <Note>
14
15 **Note:** Before you can publish private user-scoped npm packages, you must [sign up](https://npmjs.com/signup) for a paid npm user account.
16
17 Additionally, to publish private organization-scoped packages, you must [create an npm user account](https://npmjs.com/signup), then [ create a paid npm organization](https://www.npmjs.com/signup?next=/org/create).
18
19 </Note>
20
21 ## Creating a private package
22
23 1. If you are using npmrc to [manage accounts on multiple registries][reg-config], on the command line, switch to the appropriate profile:
24
25 ```
26 npmrc <profile-name>
27 ```
28
29 2. On the command line, create a directory for your package:
30
31 ```
32 mkdir my-test-package
33 ```
34
35 3. Navigate to the root directory of your package:
36
37 ```
38 cd my-test-package
39 ```
40
41 4. If you are using git to manage your package code, in the package root directory, run the following commands, replacing `git-remote-url` with the git remote URL for your package:
42
43 ```
44 git init
45 git remote add origin git://git-remote-url
46 ```
47
48 5. In the package root directory, run the `npm init` command and pass the scope to the `scope` flag:
49
50 - For an organization-scoped package, replace `my-org` with the name of your organization:
51
52 ```
53 npm init --scope=@my-org
54 ```
55
56 - For a user-scoped package, replace `my-username` with your username:
57 ```
58 npm init --scope=@my-username
59 ```
60
61 6. Respond to the prompts to generate a [`package.json`](https://docs.npmjs.com/about-package-json-and-package-lock-json-files) file. For help naming your package, see "[Package name guidelines][pkg-name]".
62
63 7. Create a [README file][readme-file] that explains what your package code is and how to use it.
64
65 8. In your preferred text editor, write the code for your package.
66
67 ## Reviewing package contents for sensitive or unnecessary information
68
69 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] (PII), and credit card data before publishing your package to the registry.** Even if your package is private, sensitive information can be exposed if the package is made public or downloaded to a computer that can be accessed by more users than intended.
70
71 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][developers].
72
73 ## Testing your package
74
75 To reduce the chances of publishing bugs, we recommend testing your package before publishing it to the npm registry. To test your package, run `npm install` with the full path to your package directory:
76
77 ```
78 npm install my-package
79 ```
80
81 ## Publishing private packages
82
83 By default, scoped packages are published with private visibility.
84
85 1. On the command line, navigate to the root directory of your package.
86
87 ```
88 cd /path/to/package
89 ```
90
91 2. To publish your private package to the npm registry, run:
92
93 ```
94 npm publish
95 ```
96
97 3. To see your private package page, visit https://npmjs.com/package/*package-name*, replacing *package-name\* with the name of your package. Private packages will say `private` below the package name on the npm website.
98
99 <>{shared['organization-package-private'].image}</>
100
101 For more information on the `publish` command, see the [CLI documentation][cli-publish].
102
103 [scopes]: about-scopes
104 [private-pkgs]: about-private-packages
105 [user-signup]: https://www.npmjs.com/signup
106 [create-org]: https://www.npmjs.com/signup?next=/org/create
107 [pkg-name]: package-name-guidelines
108 [readme-file]: about-package-readme-files
109 [developers]: /misc/developers#keeping-files-out-of-your-package
110 [cli-publish]: /cli/publish
111 [reg-config]: configuring-your-registry-settings-as-an-npm-enterprise-user#using-npmrc-to-manage-multiple-profiles-for-different-registries
112 [pii]: https://en.wikipedia.org/wiki/Personally_identifiable_information