99c1a90bf6da3e8b6e6559169b9f75592d833e6a
[platform/upstream/nodejs.git] / deps / npm / html / doc / misc / npm-scope.html
1 <!doctype html>
2 <html>
3   <title>npm-scope</title>
4   <meta http-equiv="content-type" value="text/html;utf-8">
5   <link rel="stylesheet" type="text/css" href="../../static/style.css">
6   <link rel="canonical" href="https://www.npmjs.org/doc/misc/npm-scope.html">
7   <script async=true src="../../static/toc.js"></script>
8
9   <body>
10     <div id="wrapper">
11
12 <h1><a href="../misc/npm-scope.html">npm-scope</a></h1> <p>Scoped packages</p>
13 <h2 id="description">DESCRIPTION</h2>
14 <p>All npm packages have a name. Some package names also have a scope. A scope
15 follows the usual rules for package names (url-safe characters, no leading dots
16 or underscores). When used in package names, preceded by an @-symbol and
17 followed by a slash, e.g.</p>
18 <pre><code>@somescope/somepackagename
19 </code></pre><p>Scopes are a way of grouping related packages together, and also affect a few
20 things about the way npm treats the package.</p>
21 <p><strong>As of 2014-09-03, scoped packages are not supported by the public npm registry</strong>.
22 However, the npm client is backwards-compatible with un-scoped registries, so
23 it can be used to work with scoped and un-scoped registries at the same time.</p>
24 <h2 id="installing-scoped-packages">Installing scoped packages</h2>
25 <p>Scoped packages are installed to a sub-folder of the regular installation
26 folder, e.g. if your other packages are installed in <code>node_modules/packagename</code>,
27 scoped modules will be in <code>node_modules/@myorg/packagename</code>. The scope folder
28 (<code>@myorg</code>) is simply the name of the scope preceded by an @-symbol, and can
29 contain any number of scoped packages.</p>
30 <p>A scoped package is installed by referencing it by name, preceded by an
31 @-symbol, in <code>npm install</code>:</p>
32 <pre><code>npm install @myorg/mypackage
33 </code></pre><p>Or in <code>package.json</code>:</p>
34 <pre><code>&quot;dependencies&quot;: {
35   &quot;@myorg/mypackage&quot;: &quot;^1.3.0&quot;
36 }
37 </code></pre><p>Note that if the @-symbol is omitted in either case npm will instead attempt to
38 install from GitHub; see <code><a href="../cli/npm-install.html"><a href="../cli/npm-install.html">npm-install(1)</a></a></code>.</p>
39 <h2 id="requiring-scoped-packages">Requiring scoped packages</h2>
40 <p>Because scoped packages are installed into a scope folder, you have to
41 include the name of the scope when requiring them in your code, e.g.</p>
42 <pre><code>require(&#39;@myorg/mypackage&#39;)
43 </code></pre><p>There is nothing special about the way Node treats scope folders, this is
44 just specifying to require the module <code>mypackage</code> in the folder called <code>@myorg</code>.</p>
45 <h2 id="publishing-scoped-packages">Publishing scoped packages</h2>
46 <p>Scoped packages can be published to any registry that supports them.
47 <em>As of 2014-09-03, the public npm registry does not support scoped packages</em>,
48 so attempting to publish a scoped package to the registry will fail unless
49 you have associated that scope with a different registry, see below.</p>
50 <h2 id="associating-a-scope-with-a-registry">Associating a scope with a registry</h2>
51 <p>Scopes can be associated with a separate registry. This allows you to
52 seamlessly use a mix of packages from the public npm registry and one or more
53 private registries, such as npm Enterprise.</p>
54 <p>You can associate a scope with a registry at login, e.g.</p>
55 <pre><code>npm login --registry=http://reg.example.com --scope=@myco
56 </code></pre><p>Scopes have a many-to-one relationship with registries: one registry can
57 host multiple scopes, but a scope only ever points to one registry.</p>
58 <p>You can also associate a scope with a registry using <code>npm config</code>:</p>
59 <pre><code>npm config set @myco:registry http://reg.example.com
60 </code></pre><p>Once a scope is associated with a registry, any <code>npm install</code> for a package
61 with that scope will request packages from that registry instead. Any
62 <code>npm publish</code> for a package name that contains the scope will be published to
63 that registry instead.</p>
64 <h2 id="see-also">SEE ALSO</h2>
65 <ul>
66 <li><a href="../cli/npm-install.html"><a href="../cli/npm-install.html">npm-install(1)</a></a></li>
67 <li><a href="../cli/npm-publish.html"><a href="../cli/npm-publish.html">npm-publish(1)</a></a></li>
68 </ul>
69
70 </div>
71
72 <table border=0 cellspacing=0 cellpadding=0 id=npmlogo>
73 <tr><td style="width:180px;height:10px;background:rgb(237,127,127)" colspan=18>&nbsp;</td></tr>
74 <tr><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td><td style="width:40px;height:10px;background:#fff" colspan=4>&nbsp;</td><td rowspan=4 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td><td colspan=6 style="width:60px;height:10px;background:#fff">&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=4>&nbsp;</td></tr>
75 <tr><td colspan=2 style="width:20px;height:30px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=4 colspan=2>&nbsp;</td><td style="width:10px;height:20px;background:rgb(237,127,127)" rowspan=2>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:20px;height:10px;background:#fff" rowspan=3 colspan=2>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:#fff" rowspan=3>&nbsp;</td><td style="width:10px;height:10px;background:rgb(237,127,127)" rowspan=3>&nbsp;</td></tr>
76 <tr><td style="width:10px;height:10px;background:#fff" rowspan=2>&nbsp;</td></tr>
77 <tr><td style="width:10px;height:10px;background:#fff">&nbsp;</td></tr>
78 <tr><td style="width:60px;height:10px;background:rgb(237,127,127)" colspan=6>&nbsp;</td><td colspan=10 style="width:10px;height:10px;background:rgb(237,127,127)">&nbsp;</td></tr>
79 <tr><td colspan=5 style="width:50px;height:10px;background:#fff">&nbsp;</td><td style="width:40px;height:10px;background:rgb(237,127,127)" colspan=4>&nbsp;</td><td style="width:90px;height:10px;background:#fff" colspan=9>&nbsp;</td></tr>
80 </table>
81 <p id="footer">npm-scope &mdash; npm@2.7.4</p>
82