11cb0ef41Sopenharmony_ci<!DOCTYPE html><html><head> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>scope</title> 41cb0ef41Sopenharmony_ci<style> 51cb0ef41Sopenharmony_cibody { 61cb0ef41Sopenharmony_ci background-color: #ffffff; 71cb0ef41Sopenharmony_ci color: #24292e; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci margin: 0; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci line-height: 1.5; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci#rainbar { 161cb0ef41Sopenharmony_ci height: 10px; 171cb0ef41Sopenharmony_ci background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cia { 211cb0ef41Sopenharmony_ci text-decoration: none; 221cb0ef41Sopenharmony_ci color: #0366d6; 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_cia:hover { 251cb0ef41Sopenharmony_ci text-decoration: underline; 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_cipre { 291cb0ef41Sopenharmony_ci margin: 1em 0px; 301cb0ef41Sopenharmony_ci padding: 1em; 311cb0ef41Sopenharmony_ci border: solid 1px #e1e4e8; 321cb0ef41Sopenharmony_ci border-radius: 6px; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci display: block; 351cb0ef41Sopenharmony_ci overflow: auto; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci white-space: pre; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci background-color: #f6f8fa; 401cb0ef41Sopenharmony_ci color: #393a34; 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_cicode { 431cb0ef41Sopenharmony_ci font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; 441cb0ef41Sopenharmony_ci font-size: 85%; 451cb0ef41Sopenharmony_ci padding: 0.2em 0.4em; 461cb0ef41Sopenharmony_ci background-color: #f6f8fa; 471cb0ef41Sopenharmony_ci color: #393a34; 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_cipre > code { 501cb0ef41Sopenharmony_ci padding: 0; 511cb0ef41Sopenharmony_ci background-color: inherit; 521cb0ef41Sopenharmony_ci color: inherit; 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_cih1, h2, h3 { 551cb0ef41Sopenharmony_ci font-weight: 600; 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci#logobar { 591cb0ef41Sopenharmony_ci background-color: #333333; 601cb0ef41Sopenharmony_ci margin: 0 auto; 611cb0ef41Sopenharmony_ci padding: 1em 4em; 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ci#logobar .logo { 641cb0ef41Sopenharmony_ci float: left; 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci#logobar .title { 671cb0ef41Sopenharmony_ci font-weight: 600; 681cb0ef41Sopenharmony_ci color: #dddddd; 691cb0ef41Sopenharmony_ci float: left; 701cb0ef41Sopenharmony_ci margin: 5px 0 0 1em; 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci#logobar:after { 731cb0ef41Sopenharmony_ci content: ""; 741cb0ef41Sopenharmony_ci display: block; 751cb0ef41Sopenharmony_ci clear: both; 761cb0ef41Sopenharmony_ci} 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci#content { 791cb0ef41Sopenharmony_ci margin: 0 auto; 801cb0ef41Sopenharmony_ci padding: 0 4em; 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci#table_of_contents > h2 { 841cb0ef41Sopenharmony_ci font-size: 1.17em; 851cb0ef41Sopenharmony_ci} 861cb0ef41Sopenharmony_ci#table_of_contents ul:first-child { 871cb0ef41Sopenharmony_ci border: solid 1px #e1e4e8; 881cb0ef41Sopenharmony_ci border-radius: 6px; 891cb0ef41Sopenharmony_ci padding: 1em; 901cb0ef41Sopenharmony_ci background-color: #f6f8fa; 911cb0ef41Sopenharmony_ci color: #393a34; 921cb0ef41Sopenharmony_ci} 931cb0ef41Sopenharmony_ci#table_of_contents ul { 941cb0ef41Sopenharmony_ci list-style-type: none; 951cb0ef41Sopenharmony_ci padding-left: 1.5em; 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci#table_of_contents li { 981cb0ef41Sopenharmony_ci font-size: 0.9em; 991cb0ef41Sopenharmony_ci} 1001cb0ef41Sopenharmony_ci#table_of_contents li a { 1011cb0ef41Sopenharmony_ci color: #000000; 1021cb0ef41Sopenharmony_ci} 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ciheader.title { 1051cb0ef41Sopenharmony_ci border-bottom: solid 1px #e1e4e8; 1061cb0ef41Sopenharmony_ci} 1071cb0ef41Sopenharmony_ciheader.title > h1 { 1081cb0ef41Sopenharmony_ci margin-bottom: 0.25em; 1091cb0ef41Sopenharmony_ci} 1101cb0ef41Sopenharmony_ciheader.title > .description { 1111cb0ef41Sopenharmony_ci display: block; 1121cb0ef41Sopenharmony_ci margin-bottom: 0.5em; 1131cb0ef41Sopenharmony_ci line-height: 1; 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_cifooter#edit { 1171cb0ef41Sopenharmony_ci border-top: solid 1px #e1e4e8; 1181cb0ef41Sopenharmony_ci margin: 3em 0 4em 0; 1191cb0ef41Sopenharmony_ci padding-top: 2em; 1201cb0ef41Sopenharmony_ci} 1211cb0ef41Sopenharmony_ci</style> 1221cb0ef41Sopenharmony_ci</head> 1231cb0ef41Sopenharmony_ci<body> 1241cb0ef41Sopenharmony_ci<div id="banner"> 1251cb0ef41Sopenharmony_ci<div id="rainbar"></div> 1261cb0ef41Sopenharmony_ci<div id="logobar"> 1271cb0ef41Sopenharmony_ci<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700"> 1281cb0ef41Sopenharmony_ci<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon> 1291cb0ef41Sopenharmony_ci<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon> 1301cb0ef41Sopenharmony_ci</svg> 1311cb0ef41Sopenharmony_ci<div class="title"> 1321cb0ef41Sopenharmony_cinpm command-line interface 1331cb0ef41Sopenharmony_ci</div> 1341cb0ef41Sopenharmony_ci</div> 1351cb0ef41Sopenharmony_ci</div> 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ci<section id="content"> 1381cb0ef41Sopenharmony_ci<header class="title"> 1391cb0ef41Sopenharmony_ci<h1 id="scope">scope</h1> 1401cb0ef41Sopenharmony_ci<span class="description">Scoped packages</span> 1411cb0ef41Sopenharmony_ci</header> 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci<section id="table_of_contents"> 1441cb0ef41Sopenharmony_ci<h2 id="table-of-contents">Table of contents</h2> 1451cb0ef41Sopenharmony_ci<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#installing-scoped-packages">Installing scoped packages</a></li><li><a href="#requiring-scoped-packages">Requiring scoped packages</a></li><li><a href="#publishing-scoped-packages">Publishing scoped packages</a></li><ul><li><a href="#publishing-public-scoped-packages-to-the-primary-npm-registry">Publishing public scoped packages to the primary npm registry</a></li><li><a href="#publishing-private-scoped-packages-to-the-npm-registry">Publishing private scoped packages to the npm registry</a></li></ul><li><a href="#associating-a-scope-with-a-registry">Associating a scope with a registry</a></li><li><a href="#see-also">See also</a></li></ul></div> 1461cb0ef41Sopenharmony_ci</section> 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci<div id="_content"><h3 id="description">Description</h3> 1491cb0ef41Sopenharmony_ci<p>All npm packages have a name. Some package names also have a scope. A scope 1501cb0ef41Sopenharmony_cifollows the usual rules for package names (URL-safe characters, no leading dots 1511cb0ef41Sopenharmony_cior underscores). When used in package names, scopes are preceded by an <code>@</code> symbol 1521cb0ef41Sopenharmony_ciand followed by a slash, e.g.</p> 1531cb0ef41Sopenharmony_ci<pre><code class="language-bash">@somescope/somepackagename 1541cb0ef41Sopenharmony_ci</code></pre> 1551cb0ef41Sopenharmony_ci<p>Scopes are a way of grouping related packages together, and also affect a few 1561cb0ef41Sopenharmony_cithings about the way npm treats the package.</p> 1571cb0ef41Sopenharmony_ci<p>Each npm user/organization has their own scope, and only you can add packages 1581cb0ef41Sopenharmony_ciin your scope. This means you don't have to worry about someone taking your 1591cb0ef41Sopenharmony_cipackage name ahead of you. Thus it is also a good way to signal official packages 1601cb0ef41Sopenharmony_cifor organizations.</p> 1611cb0ef41Sopenharmony_ci<p>Scoped packages can be published and installed as of <code>npm@2</code> and are supported 1621cb0ef41Sopenharmony_ciby the primary npm registry. Unscoped packages can depend on scoped packages and 1631cb0ef41Sopenharmony_civice versa. The npm client is backwards-compatible with unscoped registries, 1641cb0ef41Sopenharmony_ciso it can be used to work with scoped and unscoped registries at the same time.</p> 1651cb0ef41Sopenharmony_ci<h3 id="installing-scoped-packages">Installing scoped packages</h3> 1661cb0ef41Sopenharmony_ci<p>Scoped packages are installed to a sub-folder of the regular installation 1671cb0ef41Sopenharmony_cifolder, e.g. if your other packages are installed in <code>node_modules/packagename</code>, 1681cb0ef41Sopenharmony_ciscoped modules will be installed in <code>node_modules/@myorg/packagename</code>. The scope 1691cb0ef41Sopenharmony_cifolder (<code>@myorg</code>) is simply the name of the scope preceded by an <code>@</code> symbol, and can 1701cb0ef41Sopenharmony_cicontain any number of scoped packages.</p> 1711cb0ef41Sopenharmony_ci<p>A scoped package is installed by referencing it by name, preceded by an 1721cb0ef41Sopenharmony_ci<code>@</code> symbol, in <code>npm install</code>:</p> 1731cb0ef41Sopenharmony_ci<pre><code class="language-bash">npm install @myorg/mypackage 1741cb0ef41Sopenharmony_ci</code></pre> 1751cb0ef41Sopenharmony_ci<p>Or in <code>package.json</code>:</p> 1761cb0ef41Sopenharmony_ci<pre><code class="language-json">"dependencies": { 1771cb0ef41Sopenharmony_ci "@myorg/mypackage": "^1.3.0" 1781cb0ef41Sopenharmony_ci} 1791cb0ef41Sopenharmony_ci</code></pre> 1801cb0ef41Sopenharmony_ci<p>Note that if the <code>@</code> symbol is omitted, in either case, npm will instead attempt to 1811cb0ef41Sopenharmony_ciinstall from GitHub; see <a href="../commands/npm-install.html"><code>npm install</code></a>.</p> 1821cb0ef41Sopenharmony_ci<h3 id="requiring-scoped-packages">Requiring scoped packages</h3> 1831cb0ef41Sopenharmony_ci<p>Because scoped packages are installed into a scope folder, you have to 1841cb0ef41Sopenharmony_ciinclude the name of the scope when requiring them in your code, e.g.</p> 1851cb0ef41Sopenharmony_ci<pre><code class="language-javascript">require('@myorg/mypackage') 1861cb0ef41Sopenharmony_ci</code></pre> 1871cb0ef41Sopenharmony_ci<p>There is nothing special about the way Node treats scope folders. This 1881cb0ef41Sopenharmony_cisimply requires the <code>mypackage</code> module in the folder named <code>@myorg</code>.</p> 1891cb0ef41Sopenharmony_ci<h3 id="publishing-scoped-packages">Publishing scoped packages</h3> 1901cb0ef41Sopenharmony_ci<p>Scoped packages can be published from the CLI as of <code>npm@2</code> and can be 1911cb0ef41Sopenharmony_cipublished to any registry that supports them, including the primary npm 1921cb0ef41Sopenharmony_ciregistry.</p> 1931cb0ef41Sopenharmony_ci<p>(As of 2015-04-19, and with npm 2.0 or better, the primary npm registry 1941cb0ef41Sopenharmony_ci<strong>does</strong> support scoped packages.)</p> 1951cb0ef41Sopenharmony_ci<p>If you wish, you may associate a scope with a registry; see below.</p> 1961cb0ef41Sopenharmony_ci<h4 id="publishing-public-scoped-packages-to-the-primary-npm-registry">Publishing public scoped packages to the primary npm registry</h4> 1971cb0ef41Sopenharmony_ci<p>Publishing to a scope, you have two options:</p> 1981cb0ef41Sopenharmony_ci<ul> 1991cb0ef41Sopenharmony_ci<li>Publishing to your user scope (example: <code>@username/module</code>)</li> 2001cb0ef41Sopenharmony_ci<li>Publishing to an organization scope (example: <code>@org/module</code>)</li> 2011cb0ef41Sopenharmony_ci</ul> 2021cb0ef41Sopenharmony_ci<p>If publishing a public module to an organization scope, you must 2031cb0ef41Sopenharmony_cifirst either create an organization with the name of the scope 2041cb0ef41Sopenharmony_cithat you'd like to publish to or be added to an existing organization 2051cb0ef41Sopenharmony_ciwith the appropriate permissions. For example, if you'd like to 2061cb0ef41Sopenharmony_cipublish to <code>@org</code>, you would need to create the <code>org</code> organization 2071cb0ef41Sopenharmony_cion npmjs.com prior to trying to publish.</p> 2081cb0ef41Sopenharmony_ci<p>Scoped packages are not public by default. You will need to specify 2091cb0ef41Sopenharmony_ci<code>--access public</code> with the initial <code>npm publish</code> command. This will publish 2101cb0ef41Sopenharmony_cithe package and set access to <code>public</code> as if you had run <code>npm access public</code> 2111cb0ef41Sopenharmony_ciafter publishing. You do not need to do this when publishing new versions of 2121cb0ef41Sopenharmony_cian existing scoped package.</p> 2131cb0ef41Sopenharmony_ci<h4 id="publishing-private-scoped-packages-to-the-npm-registry">Publishing private scoped packages to the npm registry</h4> 2141cb0ef41Sopenharmony_ci<p>To publish a private scoped package to the npm registry, you must have 2151cb0ef41Sopenharmony_cian <a href="https://docs.npmjs.com/private-modules/intro">npm Private Modules</a> 2161cb0ef41Sopenharmony_ciaccount.</p> 2171cb0ef41Sopenharmony_ci<p>You can then publish the module with <code>npm publish</code> or <code>npm publish --access restricted</code>, and it will be present in the npm registry, with 2181cb0ef41Sopenharmony_cirestricted access. You can then change the access permissions, if 2191cb0ef41Sopenharmony_cidesired, with <code>npm access</code> or on the npmjs.com website.</p> 2201cb0ef41Sopenharmony_ci<h3 id="associating-a-scope-with-a-registry">Associating a scope with a registry</h3> 2211cb0ef41Sopenharmony_ci<p>Scopes can be associated with a separate registry. This allows you to 2221cb0ef41Sopenharmony_ciseamlessly use a mix of packages from the primary npm registry and one or more 2231cb0ef41Sopenharmony_ciprivate registries, such as <a href="https://github.com/features/packages">GitHub Packages</a> or the open source <a href="https://verdaccio.org">Verdaccio</a> 2241cb0ef41Sopenharmony_ciproject.</p> 2251cb0ef41Sopenharmony_ci<p>You can associate a scope with a registry at login, e.g.</p> 2261cb0ef41Sopenharmony_ci<pre><code class="language-bash">npm login --registry=http://reg.example.com --scope=@myco 2271cb0ef41Sopenharmony_ci</code></pre> 2281cb0ef41Sopenharmony_ci<p>Scopes have a many-to-one relationship with registries: one registry can 2291cb0ef41Sopenharmony_cihost multiple scopes, but a scope only ever points to one registry.</p> 2301cb0ef41Sopenharmony_ci<p>You can also associate a scope with a registry using <code>npm config</code>:</p> 2311cb0ef41Sopenharmony_ci<pre><code class="language-bash">npm config set @myco:registry=http://reg.example.com 2321cb0ef41Sopenharmony_ci</code></pre> 2331cb0ef41Sopenharmony_ci<p>Once a scope is associated with a registry, any <code>npm install</code> for a package 2341cb0ef41Sopenharmony_ciwith that scope will request packages from that registry instead. Any 2351cb0ef41Sopenharmony_ci<code>npm publish</code> for a package name that contains the scope will be published to 2361cb0ef41Sopenharmony_cithat registry instead.</p> 2371cb0ef41Sopenharmony_ci<h3 id="see-also">See also</h3> 2381cb0ef41Sopenharmony_ci<ul> 2391cb0ef41Sopenharmony_ci<li><a href="../commands/npm-install.html">npm install</a></li> 2401cb0ef41Sopenharmony_ci<li><a href="../commands/npm-publish.html">npm publish</a></li> 2411cb0ef41Sopenharmony_ci<li><a href="../commands/npm-access.html">npm access</a></li> 2421cb0ef41Sopenharmony_ci<li><a href="../using-npm/registry.html">npm registry</a></li> 2431cb0ef41Sopenharmony_ci</ul></div> 2441cb0ef41Sopenharmony_ci 2451cb0ef41Sopenharmony_ci<footer id="edit"> 2461cb0ef41Sopenharmony_ci<a href="https://github.com/npm/cli/edit/latest/docs/content/using-npm/scope.md"> 2471cb0ef41Sopenharmony_ci<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;"> 2481cb0ef41Sopenharmony_ci<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path> 2491cb0ef41Sopenharmony_ci</svg> 2501cb0ef41Sopenharmony_ciEdit this page on GitHub 2511cb0ef41Sopenharmony_ci</a> 2521cb0ef41Sopenharmony_ci</footer> 2531cb0ef41Sopenharmony_ci</section> 2541cb0ef41Sopenharmony_ci 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ci</body></html>