1 npm-scope(7) -- Scoped packages
2 ===============================
6 All npm packages have a name. Some package names also have a scope. A scope
7 follows the usual rules for package names (url-safe characters, no leading dots
8 or underscores). When used in package names, preceded by an @-symbol and
9 followed by a slash, e.g.
11 @somescope/somepackagename
13 Scopes are a way of grouping related packages together, and also affect a few
14 things about the way npm treats the package.
16 Scoped packages can be published and installed as of `npm@2` and are supported
17 by the primary npm registry. The npm client is backwards-compatible with
18 un-scoped registries, so it can be used to work with scoped and un-scoped
19 registries at the same time.
21 ## Installing scoped packages
23 Scoped packages are installed to a sub-folder of the regular installation
24 folder, e.g. if your other packages are installed in `node_modules/packagename`,
25 scoped modules will be in `node_modules/@myorg/packagename`. The scope folder
26 (`@myorg`) is simply the name of the scope preceded by an @-symbol, and can
27 contain any number of scoped packages.
29 A scoped package is installed by referencing it by name, preceded by an
30 @-symbol, in `npm install`:
32 npm install @myorg/mypackage
37 "@myorg/mypackage": "^1.3.0"
40 Note that if the @-symbol is omitted in either case npm will instead attempt to
41 install from GitHub; see `npm-install(1)`.
43 ## Requiring scoped packages
45 Because scoped packages are installed into a scope folder, you have to
46 include the name of the scope when requiring them in your code, e.g.
48 require('@myorg/mypackage')
50 There is nothing special about the way Node treats scope folders, this is
51 just specifying to require the module `mypackage` in the folder called `@myorg`.
53 ## Publishing scoped packages
55 Scoped packages can be published from the CLI as of `npm@2` and can be
56 published to any registry that supports them, including the primary npm
59 (As of 2015-04-19, and with npm 2.0 or newer, the primary npm registry **does**
60 support scoped packages)
62 If you wish, you may associate a scope with a registry; see below.
64 ### Publishing public scoped packages to the primary npm registry
66 To publish a public scoped package, you must specify `--access public` with
67 the initial publication. This will publish the package and set access
68 to `public` as if you had run `npm access public` after publishing.
70 ### Publishing private scoped packages to the npm registry
72 To publish a private scoped package to the npm registry, you must have
73 an [npm Private Modules](https://www.npmjs.com/private-modules)
76 You can then publish the module with `npm publish` or `npm publish
77 --access restricted`, and it will be present in the npm registry, with
78 restricted access. You can then change the access permissions, if
79 desired, with `npm access` or on the npmjs.com website.
81 ## Associating a scope with a registry
83 Scopes can be associated with a separate registry. This allows you to
84 seamlessly use a mix of packages from the primary npm registry and one or more
85 private registries, such as npm Enterprise.
87 You can associate a scope with a registry at login, e.g.
89 npm login --registry=http://reg.example.com --scope=@myco
91 Scopes have a many-to-one relationship with registries: one registry can
92 host multiple scopes, but a scope only ever points to one registry.
94 You can also associate a scope with a registry using `npm config`:
96 npm config set @myco:registry http://reg.example.com
98 Once a scope is associated with a registry, any `npm install` for a package
99 with that scope will request packages from that registry instead. Any
100 `npm publish` for a package name that contains the scope will be published to
101 that registry instead.