11cb0ef41Sopenharmony_ci---
21cb0ef41Sopenharmony_cititle: npm-publish
31cb0ef41Sopenharmony_cisection: 1
41cb0ef41Sopenharmony_cidescription: Publish a package
51cb0ef41Sopenharmony_ci---
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci### Synopsis
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci```bash
101cb0ef41Sopenharmony_cinpm publish <package-spec>
111cb0ef41Sopenharmony_ci```
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci### Description
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciPublishes a package to the registry so that it can be installed by name.
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciBy default npm will publish to the public registry. This can be
181cb0ef41Sopenharmony_cioverridden by specifying a different default registry or using a
191cb0ef41Sopenharmony_ci[`scope`](/using-npm/scope) in the name, combined with a
201cb0ef41Sopenharmony_ciscope-configured registry (see
211cb0ef41Sopenharmony_ci[`package.json`](/configuring-npm/package-json)).
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciA `package` is interpreted the same way as other commands (like
251cb0ef41Sopenharmony_ci`npm install`) and can be:
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci* a) a folder containing a program described by a
281cb0ef41Sopenharmony_ci  [`package.json`](/configuring-npm/package-json) file
291cb0ef41Sopenharmony_ci* b) a gzipped tarball containing (a)
301cb0ef41Sopenharmony_ci* c) a url that resolves to (b)
311cb0ef41Sopenharmony_ci* d) a `<name>@<version>` that is published on the registry (see
321cb0ef41Sopenharmony_ci  [`registry`](/using-npm/registry)) with (c)
331cb0ef41Sopenharmony_ci* e) a `<name>@<tag>` (see [`npm dist-tag`](/commands/npm-dist-tag)) that
341cb0ef41Sopenharmony_ci  points to (d)
351cb0ef41Sopenharmony_ci* f) a `<name>` that has a "latest" tag satisfying (e)
361cb0ef41Sopenharmony_ci* g) a `<git remote url>` that resolves to (a)
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciThe publish will fail if the package name and version combination already
391cb0ef41Sopenharmony_ciexists in the specified registry.
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciOnce a package is published with a given name and version, that specific
421cb0ef41Sopenharmony_ciname and version combination can never be used again, even if it is removed
431cb0ef41Sopenharmony_ciwith [`npm unpublish`](/commands/npm-unpublish).
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciAs of `npm@5`, both a sha1sum and an integrity field with a sha512sum of the
461cb0ef41Sopenharmony_citarball will be submitted to the registry during publication. Subsequent
471cb0ef41Sopenharmony_ciinstalls will use the strongest supported algorithm to verify downloads.
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciSimilar to `--dry-run` see [`npm pack`](/commands/npm-pack), which figures
501cb0ef41Sopenharmony_ciout the files to be included and packs them into a tarball to be uploaded
511cb0ef41Sopenharmony_cito the registry.
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci### Files included in package
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciTo see what will be included in your package, run `npm pack --dry-run`.  All
561cb0ef41Sopenharmony_cifiles are included by default, with the following exceptions:
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci- Certain files that are relevant to package installation and distribution
591cb0ef41Sopenharmony_ci  are always included.  For example, `package.json`, `README.md`,
601cb0ef41Sopenharmony_ci  `LICENSE`, and so on.
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci- If there is a "files" list in
631cb0ef41Sopenharmony_ci  [`package.json`](/configuring-npm/package-json), then only the files
641cb0ef41Sopenharmony_ci  specified will be included.  (If directories are specified, then they
651cb0ef41Sopenharmony_ci  will be walked recursively and their contents included, subject to the
661cb0ef41Sopenharmony_ci  same ignore rules.)
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci- If there is a `.gitignore` or `.npmignore` file, then ignored files in
691cb0ef41Sopenharmony_ci  that and all child directories will be excluded from the package.  If
701cb0ef41Sopenharmony_ci  _both_ files exist, then the `.gitignore` is ignored, and only the
711cb0ef41Sopenharmony_ci  `.npmignore` is used.
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci  `.npmignore` files follow the [same pattern
741cb0ef41Sopenharmony_ci  rules](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring)
751cb0ef41Sopenharmony_ci  as `.gitignore` files
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci- If the file matches certain patterns, then it will _never_ be included,
781cb0ef41Sopenharmony_ci  unless explicitly added to the `"files"` list in `package.json`, or
791cb0ef41Sopenharmony_ci  un-ignored with a `!` rule in a `.npmignore` or `.gitignore` file.
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci- Symbolic links are never included in npm packages.
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ciSee [`developers`](/using-npm/developers) for full details on what's
851cb0ef41Sopenharmony_ciincluded in the published package, as well as details on how the package is
861cb0ef41Sopenharmony_cibuilt.
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci### Configuration
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci#### `tag`
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci* Default: "latest"
931cb0ef41Sopenharmony_ci* Type: String
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ciIf you ask npm to install a package and don't tell it a specific version,
961cb0ef41Sopenharmony_cithen it will install the specified tag.
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ciAlso the tag that is added to the package@version specified by the `npm tag`
991cb0ef41Sopenharmony_cicommand, if no explicit tag is given.
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ciWhen used by the `npm diff` command, this is the tag used to fetch the
1021cb0ef41Sopenharmony_citarball that will be compared with the local files by default.
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci#### `access`
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci* Default: 'public' for new packages, existing packages it will not change the
1091cb0ef41Sopenharmony_ci  current level
1101cb0ef41Sopenharmony_ci* Type: null, "restricted", or "public"
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ciIf you do not want your scoped package to be publicly viewable (and
1131cb0ef41Sopenharmony_ciinstallable) set `--access=restricted`.
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciUnscoped packages can not be set to `restricted`.
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ciNote: This defaults to not changing the current access level for existing
1181cb0ef41Sopenharmony_cipackages. Specifying a value of `restricted` or `public` during publish will
1191cb0ef41Sopenharmony_cichange the access for an existing package the same way that `npm access set
1201cb0ef41Sopenharmony_cistatus` would.
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci#### `dry-run`
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci* Default: false
1271cb0ef41Sopenharmony_ci* Type: Boolean
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ciIndicates that you don't want npm to make any changes and that it should
1301cb0ef41Sopenharmony_cionly report what it would have done. This can be passed into any of the
1311cb0ef41Sopenharmony_cicommands that modify your local installation, eg, `install`, `update`,
1321cb0ef41Sopenharmony_ci`dedupe`, `uninstall`, as well as `pack` and `publish`.
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ciNote: This is NOT honored by other network related commands, eg `dist-tags`,
1351cb0ef41Sopenharmony_ci`owner`, etc.
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci#### `otp`
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci* Default: null
1421cb0ef41Sopenharmony_ci* Type: null or String
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciThis is a one-time password from a two-factor authenticator. It's needed
1451cb0ef41Sopenharmony_ciwhen publishing or changing package permissions with `npm access`.
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ciIf not set, and a registry response fails with a challenge for a one-time
1481cb0ef41Sopenharmony_cipassword, npm will prompt on the command line for one.
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci#### `workspace`
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci* Default:
1551cb0ef41Sopenharmony_ci* Type: String (can be set multiple times)
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the
1581cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by
1591cb0ef41Sopenharmony_cithis configuration option.
1601cb0ef41Sopenharmony_ci
1611cb0ef41Sopenharmony_ciValid values for the `workspace` config are either:
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci* Workspace names
1641cb0ef41Sopenharmony_ci* Path to a workspace directory
1651cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all
1661cb0ef41Sopenharmony_ci  workspaces within that folder)
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a
1691cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a
1701cb0ef41Sopenharmony_cibrand new workspace within the project.
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci#### `workspaces`
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci* Default: null
1771cb0ef41Sopenharmony_ci* Type: null or Boolean
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ciSet to true to run the command in the context of **all** configured
1801cb0ef41Sopenharmony_ciworkspaces.
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ciExplicitly setting this to false will cause commands like `install` to
1831cb0ef41Sopenharmony_ciignore workspaces altogether. When not set explicitly:
1841cb0ef41Sopenharmony_ci
1851cb0ef41Sopenharmony_ci- Commands that operate on the `node_modules` tree (install, update, etc.)
1861cb0ef41Sopenharmony_ciwill link workspaces into the `node_modules` folder. - Commands that do
1871cb0ef41Sopenharmony_ciother things (test, exec, publish, etc.) will operate on the root project,
1881cb0ef41Sopenharmony_ci_unless_ one or more workspaces are specified in the `workspace` config.
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci#### `include-workspace-root`
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci* Default: false
1951cb0ef41Sopenharmony_ci* Type: Boolean
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ciInclude the workspace root when workspaces are enabled for a command.
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ciWhen false, specifying individual workspaces via the `workspace` config, or
2001cb0ef41Sopenharmony_ciall workspaces via the `workspaces` flag, will cause npm to operate only on
2011cb0ef41Sopenharmony_cithe specified workspaces, and not on the root project.
2021cb0ef41Sopenharmony_ci
2031cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci#### `provenance`
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci* Default: false
2081cb0ef41Sopenharmony_ci* Type: Boolean
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ciWhen publishing from a supported cloud CI/CD system, the package will be
2111cb0ef41Sopenharmony_cipublicly linked to where it was built and published from.
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ciThis config can not be used with: `provenance-file`
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ci#### `provenance-file`
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ci* Default: null
2181cb0ef41Sopenharmony_ci* Type: Path
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ciWhen publishing, the provenance bundle at the given path will be used.
2211cb0ef41Sopenharmony_ci
2221cb0ef41Sopenharmony_ciThis config can not be used with: `provenance`
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci### See Also
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ci* [package spec](/using-npm/package-spec)
2271cb0ef41Sopenharmony_ci* [npm-packlist package](http://npm.im/npm-packlist)
2281cb0ef41Sopenharmony_ci* [npm registry](/using-npm/registry)
2291cb0ef41Sopenharmony_ci* [npm scope](/using-npm/scope)
2301cb0ef41Sopenharmony_ci* [npm adduser](/commands/npm-adduser)
2311cb0ef41Sopenharmony_ci* [npm owner](/commands/npm-owner)
2321cb0ef41Sopenharmony_ci* [npm deprecate](/commands/npm-deprecate)
2331cb0ef41Sopenharmony_ci* [npm dist-tag](/commands/npm-dist-tag)
2341cb0ef41Sopenharmony_ci* [npm pack](/commands/npm-pack)
2351cb0ef41Sopenharmony_ci* [npm profile](/commands/npm-profile)
236