1NPM-PUBLISH(1) NPM-PUBLISH(1)
2
3
4
6 npm-publish - Publish a package
7
8 Synopsis
9 npm publish [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>] [--otp otpcode] [--dry-run]
10
11 Publishes '.' if no argument supplied
12 Sets tag 'latest' if no --tag specified
13
14 Description
15 Publishes a package to the registry so that it can be installed by
16 name.
17
18 By default npm will publish to the public registry. This can be over‐
19 ridden by specifying a different default registry or using a npm help
20 scope in the name (see npm help package.json).
21
22 • <folder>: A folder containing a package.json file
23
24 • <tarball>: A url or file path to a gzipped tar archive containing a
25 single folder with a package.json file inside.
26
27 • [--tag <tag>]: Registers the published package with the given tag,
28 such that npm install <name>@<tag> will install this version. By de‐
29 fault, npm publish updates and npm install installs the latest tag.
30 See npm-dist-tag npm-dist-tag for details about tags.
31
32 • [--access <public|restricted>]: Tells the registry whether this pack‐
33 age should be published as public or restricted. Only applies to
34 scoped packages, which default to restricted. If you don't have a
35 paid account, you must publish with --access public to publish scoped
36 packages.
37
38 • [--otp <otpcode>]: If you have two-factor authentication enabled in
39 auth-and-writes mode then you can provide a code from your authenti‐
40 cator with this. If you don't include this and you're running from a
41 TTY then you'll be prompted.
42
43 • [--dry-run]: As of npm@6, does everything publish would do except ac‐
44 tually publishing to the registry. Reports the details of what would
45 have been published.
46
47 • [--workspaces]: Enables workspace context while publishing. All
48 workspace packages will be published.
49
50 • [--workspace]: Enables workspaces context and limits results to only
51 those specified by this config item. Only the packages in the
52 workspaces given will be published.
53
54
55 The publish will fail if the package name and version combination al‐
56 ready exists in the specified registry.
57
58 Once a package is published with a given name and version, that spe‐
59 cific name and version combination can never be used again, even if it
60 is removed with npm help unpublish.
61
62 As of npm@5, both a sha1sum and an integrity field with a sha512sum of
63 the tarball will be submitted to the registry during publication. Sub‐
64 sequent installs will use the strongest supported algorithm to verify
65 downloads.
66
67 Similar to --dry-run see npm help pack, which figures out the files to
68 be included and packs them into a tarball to be uploaded to the reg‐
69 istry.
70
71 Files included in package
72 To see what will be included in your package, run npx npm-packlist.
73 All files are included by default, with the following exceptions:
74
75 • Certain files that are relevant to package installation and distribu‐
76 tion are always included. For example, package.json, README.md, LI‐
77 CENSE, and so on.
78
79 • If there is a "files" list in npm help package.json, then only the
80 files specified will be included. (If directories are specified,
81 then they will be walked recursively and their contents included,
82 subject to the same ignore rules.)
83
84 • If there is a .gitignore or .npmignore file, then ignored files in
85 that and all child directories will be excluded from the package. If
86 both files exist, then the .gitignore is ignored, and only the
87 .npmignore is used. .npmignore files follow the same pattern rules
88 https://git-scm.com/book/en/v2/Git-Basics-Record‐
89 ing-Changes-to-the-Repository#_ignoring as .gitignore files
90
91 • If the file matches certain patterns, then it will never be included,
92 unless explicitly added to the "files" list in package.json, or
93 un-ignored with a ! rule in a .npmignore or .gitignore file.
94
95 • Symbolic links are never included in npm packages.
96
97
98 See npm help developers for full details on what's included in the pub‐
99 lished package, as well as details on how the package is built.
100
101 Configuration
102 <!-- AUTOGENERATED CONFIG DESCRIPTIONS START --> <!-- automatically
103 generated, do not edit manually --> <!-- see lib/utils/config/defini‐
104 tions.js -->
105
106 tag
107 • Default: "latest"
108
109 • Type: String
110
111
112 If you ask npm to install a package and don't tell it a specific ver‐
113 sion, then it will install the specified tag.
114
115 Also the tag that is added to the package@version specified by the npm
116 tag command, if no explicit tag is given.
117
118 When used by the npm diff command, this is the tag used to fetch the
119 tarball that will be compared with the local files by default. <!--
120 automatically generated, do not edit manually --> <!-- see
121 lib/utils/config/definitions.js -->
122
123
124 access
125 • Default: 'restricted' for scoped packages, 'public' for unscoped
126 packages
127
128 • Type: null, "restricted", or "public"
129
130
131 When publishing scoped packages, the access level defaults to re‐
132 stricted. If you want your scoped package to be publicly viewable (and
133 installable) set --access=public. The only valid values for access are
134 public and restricted. Unscoped packages always have an access level of
135 public.
136
137 Note: Using the --access flag on the npm publish command will only set
138 the package access level on the initial publish of the package. Any
139 subsequent npm publish commands using the --access flag will not have
140 an effect to the access level. To make changes to the access level af‐
141 ter the initial publish use npm access. <!-- automatically generated,
142 do not edit manually --> <!-- see lib/utils/config/definitions.js -->
143
144
145 dry-run
146 • Default: false
147
148 • Type: Boolean
149
150
151 Indicates that you don't want npm to make any changes and that it
152 should only report what it would have done. This can be passed into any
153 of the commands that modify your local installation, eg, install, up‐
154 date, dedupe, uninstall, as well as pack and publish.
155
156 Note: This is NOT honored by other network related commands, eg
157 dist-tags, owner, etc. <!-- automatically generated, do not edit manu‐
158 ally --> <!-- see lib/utils/config/definitions.js -->
159
160
161 otp
162 • Default: null
163
164 • Type: null or String
165
166
167 This is a one-time password from a two-factor authenticator. It's
168 needed when publishing or changing package permissions with npm access.
169
170 If not set, and a registry response fails with a challenge for a
171 one-time password, npm will prompt on the command line for one. <!--
172 automatically generated, do not edit manually --> <!-- see
173 lib/utils/config/definitions.js -->
174
175
176 workspace
177 • Default:
178
179 • Type: String (can be set multiple times)
180
181
182 Enable running a command in the context of the configured workspaces of
183 the current project while filtering by running only the workspaces de‐
184 fined by this configuration option.
185
186 Valid values for the workspace config are either:
187
188 • Workspace names
189
190 • Path to a workspace directory
191
192 • Path to a parent workspace directory (will result to selecting all of
193 the nested workspaces)
194
195
196 When set for the npm init command, this may be set to the folder of a
197 workspace which does not yet exist, to create the folder and set it up
198 as a brand new workspace within the project.
199
200 This value is not exported to the environment for child processes.
201 <!-- automatically generated, do not edit manually --> <!-- see
202 lib/utils/config/definitions.js -->
203
204
205 workspaces
206 • Default: false
207
208 • Type: Boolean
209
210
211 Enable running a command in the context of all the configured
212 workspaces.
213
214 This value is not exported to the environment for child processes.
215 <!-- automatically generated, do not edit manually --> <!-- see
216 lib/utils/config/definitions.js -->
217
218 <!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
219
220
221 See Also
222 • npm-packlist package http://npm.im/npm-packlist
223
224 • npm help registry
225
226 • npm help scope
227
228 • npm help adduser
229
230 • npm help owner
231
232 • npm help deprecate
233
234 • npm help dist-tag
235
236 • npm help pack
237
238 • npm help profile
239
240
241
242
243 October 2021 NPM-PUBLISH(1)