Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
developers.html375 linesDownload Raw Back to using-npm
1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>Developers</title>
4<style>
5body {
6    background-color: #ffffff;
7    color: #24292e;
8
9    margin: 0;
10
11    line-height: 1.5;
12
13    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
14}
15#rainbar {
16    height: 10px;
17    background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
18}
19
20a {
21    text-decoration: none;
22    color: #0366d6;
23}
24a:hover {
25    text-decoration: underline;
26}
27
28pre {
29    margin: 1em 0px;
30    padding: 1em;
31    border: solid 1px #e1e4e8;
32    border-radius: 6px;
33
34    display: block;
35    overflow: auto;
36
37    white-space: pre;
38
39    background-color: #f6f8fa;
40    color: #393a34;
41}
42code {
43    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
44    font-size: 85%;
45    padding: 0.2em 0.4em;
46    background-color: #f6f8fa;
47    color: #393a34;
48}
49pre > code {
50    padding: 0;
51    background-color: inherit;
52    color: inherit;
53}
54h1, h2, h3 {
55    font-weight: 600;
56}
57
58#logobar {
59    background-color: #333333;
60    margin: 0 auto;
61    padding: 1em 4em;
62}
63#logobar .logo {
64    float: left;
65}
66#logobar .title {
67    font-weight: 600;
68    color: #dddddd;
69    float: left;
70    margin: 5px 0 0 1em;
71}
72#logobar:after {
73    content: "";
74    display: block;
75    clear: both;
76}
77
78#content {
79    margin: 0 auto;
80    padding: 0 4em;
81}
82
83#table_of_contents > h2 {
84    font-size: 1.17em;
85}
86#table_of_contents ul:first-child {
87    border: solid 1px #e1e4e8;
88    border-radius: 6px;
89    padding: 1em;
90    background-color: #f6f8fa;
91    color: #393a34;
92}
93#table_of_contents ul {
94    list-style-type: none;
95    padding-left: 1.5em;
96}
97#table_of_contents li {
98    font-size: 0.9em;
99}
100#table_of_contents li a {
101    color: #000000;
102}
103
104header.title {
105    border-bottom: solid 1px #e1e4e8;
106}
107header.title > h1 {
108    margin-bottom: 0.25em;
109}
110header.title > .description {
111    display: block;
112    margin-bottom: 0.5em;
113    line-height: 1;
114}
115
116header.title .version {
117    font-size: 0.8em;
118    color: #666666;
119}
120
121footer#edit {
122    border-top: solid 1px #e1e4e8;
123    margin: 3em 0 4em 0;
124    padding-top: 2em;
125}
126
127table {
128    width: 100%;
129    margin: 1em 0;
130    border-radius: 6px;
131    border: 1px solid #e1e4e8;
132    overflow: hidden;
133    border-collapse: separate;
134    border-spacing: 0;
135}
136
137table thead {
138    background-color: #f6f8fa;
139}
140
141table tbody {
142    background-color: #ffffff;
143}
144
145table th,
146table td {
147    padding: 0.75em;
148    text-align: left;
149    border-right: 1px solid #e1e4e8;
150    border-bottom: 1px solid #e1e4e8;
151}
152
153table th:last-child,
154table td:last-child {
155    border-right: none;
156}
157
158table tbody tr:last-child td {
159    border-bottom: none;
160}
161
162table th {
163    font-weight: 600;
164    background-color: #f6f8fa;
165}
166
167table code {
168    white-space: nowrap;
169}
170
171</style>
172</head>
173<body>
174<div id="banner">
175<div id="rainbar"></div>
176<div id="logobar">
177<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
178<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
179<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
180</svg>
181<div class="title">
182npm command-line interface
183</div>
184</div>
185</div>
186
187<section id="content">
188<header class="title">
189<h1 id="----developers----11121">
190    <span>Developers</span>
191    <span class="version">@11.12.1</span>
192</h1>
193<span class="description">Developer guide</span>
194</header>
195
196<section id="table_of_contents">
197<h2 id="table-of-contents">Table of contents</h2>
198<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#about-these-documents">About These Documents</a></li><li><a href="#what-is-a-package">What is a Package</a></li><li><a href="#the-packagejson-file">The package.json File</a></li><li><a href="#keeping-files-out-of-your-package">Keeping files <em>out</em> of your Package</a></li><ul><li><a href="#testing-whether-your-npmignore-or-files-config-works">Testing whether your <code>.npmignore</code> or <code>files</code> config works</a></li></ul><li><a href="#link-packages">Link Packages</a></li><li><a href="#before-publishing-make-sure-your-package-installs-and-works">Before Publishing: Make Sure Your Package Installs and Works</a></li><li><a href="#create-a-user-account">Create a User Account</a></li><li><a href="#publish-your-package">Publish your Package</a></li><li><a href="#brag-about-it">Brag about it</a></li><li><a href="#see-also">See also</a></li></ul></div>
199</section>
200
201<div id="_content"><h3 id="description">Description</h3>
202<p>So, you've decided to use npm to develop (and maybe publish/deploy) your project.</p>
203<p>Fantastic!</p>
204<p>There are a few things that you need to do above the simple steps that your users will do to install your program.</p>
205<h3 id="about-these-documents">About These Documents</h3>
206<p>These are man pages.
207If you install npm, you should be able to then do <code>man npm-thing</code> to get the documentation on a particular topic, or <code>npm help thing</code> to see the same information.</p>
208<h3 id="what-is-a-package">What is a Package</h3>
209<p>A package is:</p>
210<ul>
211<li>a) a folder containing a program described by a package.json file</li>
212<li>b) a gzipped tarball containing (a)</li>
213<li>c) a url that resolves to (b)</li>
214<li>d) a <code>&lt;name&gt;@&lt;version&gt;</code> that is published on the registry with (c)</li>
215<li>e) a <code>&lt;name&gt;@&lt;tag&gt;</code> that points to (d)</li>
216<li>f) a <code>&lt;name&gt;</code> that has a "latest" tag satisfying (e)</li>
217<li>g) a <code>git</code> url that, when cloned, results in (a).</li>
218</ul>
219<p>Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b).</p>
220<p>Git urls can be of the form:</p>
221<pre><code class="language-bash">git://github.com/user/project.git#commit-ish
222git+ssh://user@hostname:project.git#commit-ish
223git+http://user@hostname/project/blah.git#commit-ish
224git+https://user@hostname/project/blah.git#commit-ish
225</code></pre>
226<p>The <code>commit-ish</code> can be any tag, sha, or branch which can be supplied as an argument to <code>git checkout</code>.
227The default is whatever the repository uses as its default branch.</p>
228<h3 id="the-packagejson-file">The package.json File</h3>
229<p>You need to have a <code>package.json</code> file in the root of your project to do much of anything with npm.
230That is basically the whole interface.</p>
231<p>See <a href="../configuring-npm/package-json.html"><code>package.json</code></a> for details about what goes in that file.
232At the very least, you need:</p>
233<ul>
234<li>
235<p>name: This should be a string that identifies your project.
236Please do not use the name to specify that it runs on node, or is in JavaScript.
237You can use the "engines" field to explicitly state the versions of node (or whatever else) that your program requires, and it's pretty well assumed that it's JavaScript.</p>
238<p>It does not necessarily need to match your github repository name.</p>
239<p>So, <code>node-foo</code> and <code>bar-js</code> are bad names.
240<code>foo</code> or <code>bar</code> are better.</p>
241</li>
242<li>
243<p>version: A semver-compatible version.</p>
244</li>
245<li>
246<p>engines: Specify the versions of node (or whatever else) that your program runs on.
247The node API changes a lot, and there may be bugs or new functionality that you depend on.
248Be explicit.</p>
249</li>
250<li>
251<p>author: Take some credit.</p>
252</li>
253<li>
254<p>scripts: If you have a special compilation or installation script, then you should put it in the <code>scripts</code> object.
255You should definitely have at least a basic smoke-test command as the "scripts.test" field.
256See <a href="../using-npm/scripts.html">scripts</a>.</p>
257</li>
258<li>
259<p>main: If you have a single module that serves as the entry point to your program (like what the "foo" package gives you at require("foo")), then you need to specify that in the "main" field.</p>
260</li>
261<li>
262<p>directories: This is an object mapping names to folders.
263The best ones to include are "lib" and "doc", but if you use "man" to specify a folder full of man pages, they'll get installed just like these ones.</p>
264</li>
265</ul>
266<p>You can use <code>npm init</code> in the root of your package in order to get you started with a pretty basic package.json file.
267See <a href="../commands/npm-init.html"><code>npm init</code></a> for more info.</p>
268<h3 id="keeping-files-out-of-your-package">Keeping files <em>out</em> of your Package</h3>
269<p>Use a <code>.npmignore</code> file to keep stuff out of your package.
270If there's no <code>.npmignore</code> file, but there <em>is</em> a <code>.gitignore</code> file, then npm will ignore the stuff matched by the <code>.gitignore</code> file.
271If you <em>want</em> to include something that is excluded by your <code>.gitignore</code> file, you can create an empty <code>.npmignore</code> file to override it.
272Like <code>git</code>, <code>npm</code> looks for <code>.npmignore</code> and <code>.gitignore</code> files in all subdirectories of your package, not only the root directory.</p>
273<p><code>.npmignore</code> files follow the <a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring">same pattern rules</a> as <code>.gitignore</code> files:</p>
274<ul>
275<li>Blank lines or lines starting with <code>#</code> are ignored.</li>
276<li>Standard glob patterns work.</li>
277<li>You can end patterns with a forward slash <code>/</code> to specify a directory.</li>
278<li>You can negate a pattern by starting it with an exclamation point <code>!</code>.</li>
279</ul>
280<p>By default, some paths and files are ignored, so there's no need to add them to <code>.npmignore</code> explicitly.
281Some examples are:</p>
282<ul>
283<li><code>.*.swp</code></li>
284<li><code>._*</code></li>
285<li><code>.DS_Store</code></li>
286<li><code>.git</code></li>
287<li><code>.gitignore</code></li>
288<li><code>.hg</code></li>
289<li><code>.npmignore</code></li>
290<li><code>.npmrc</code></li>
291<li><code>.lock-wscript</code></li>
292<li><code>.svn</code></li>
293<li><code>.wafpickle-*</code></li>
294<li><code>config.gypi</code></li>
295<li><code>CVS</code></li>
296<li><code>npm-debug.log</code></li>
297</ul>
298<p>Additionally, everything in <code>node_modules</code> is ignored, except for bundled dependencies.
299npm automatically handles this for you, so don't bother adding <code>node_modules</code> to <code>.npmignore</code>.</p>
300<p>The following paths and files are never ignored, so adding them to <code>.npmignore</code> is pointless:</p>
301<ul>
302<li><code>package.json</code></li>
303<li><code>README</code> (and its variants)</li>
304<li><code>LICENSE</code> / <code>LICENCE</code></li>
305</ul>
306<p>If, given the structure of your project, you find <code>.npmignore</code> to be a maintenance headache, you might instead try populating the <code>files</code> property of <code>package.json</code>, which is an array of file or directory names that should be included in your package.
307Sometimes manually picking which items to allow is easier to manage than building a block list.</p>
308<p>See <a href="../configuring-npm/package-json.html"><code>package.json</code></a> for more info on what can and can't be ignored.</p>
309<h4 id="testing-whether-your-npmignore-or-files-config-works">Testing whether your <code>.npmignore</code> or <code>files</code> config works</h4>
310<p>If you want to double check that your package will include only the files you intend it to when published, you can run the <code>npm pack</code> command locally which will generate a tarball in the working directory, the same way it does for publishing.</p>
311<h3 id="link-packages">Link Packages</h3>
312<p><code>npm link</code> is designed to install a development package and see the changes in real time without having to keep re-installing it.
313(You do need to either re-link or <code>npm rebuild -g</code> to update compiled packages, of course.)</p>
314<p>More info at <a href="../commands/npm-link.html"><code>npm link</code></a>.</p>
315<h3 id="before-publishing-make-sure-your-package-installs-and-works">Before Publishing: Make Sure Your Package Installs and Works</h3>
316<p><strong>This is important.</strong></p>
317<p>If you cannot install it locally, you'll have problems trying to publish it.
318Or, worse yet, you'll be able to publish it, but you'll be publishing a broken or pointless package.
319So don't do that.</p>
320<p>In the root of your package, do this:</p>
321<pre><code class="language-bash">npm install . -g
322</code></pre>
323<p>That'll show you that it's working.
324If you'd rather just create a symlink package that points to your working directory, then do this:</p>
325<pre><code class="language-bash">npm link
326</code></pre>
327<p>Use <code>npm ls -g</code> to see if it's there.</p>
328<p>To test a local install, go into some other folder, and then do:</p>
329<pre><code class="language-bash">cd ../some-other-folder
330npm install ../my-package
331</code></pre>
332<p>to install it locally into the node_modules folder in that other place.</p>
333<p>Then go into the node-repl, and try using require("my-thing") to bring in your module's main module.</p>
334<h3 id="create-a-user-account">Create a User Account</h3>
335<p>Create a user with the adduser command.
336It works like this:</p>
337<pre><code class="language-bash">npm adduser
338</code></pre>
339<p>and then follow the prompts.</p>
340<p>This is documented better in <a href="../commands/npm-adduser.html">npm adduser</a>.</p>
341<h3 id="publish-your-package">Publish your Package</h3>
342<p>This part's easy.
343In the root of your folder, do this:</p>
344<pre><code class="language-bash">npm publish
345</code></pre>
346<p>You can give publish a url to a tarball, or a filename of a tarball, or a path to a folder.</p>
347<p>Note that pretty much <strong>everything in that folder will be exposed</strong> by default.
348So, if you have secret stuff in there, use a <code>.npmignore</code> file to list out the globs to ignore, or publish from a fresh checkout.</p>
349<h3 id="brag-about-it">Brag about it</h3>
350<p>Send emails, write blogs, blab in IRC.</p>
351<p>Tell the world how easy it is to install your program!</p>
352<h3 id="see-also">See also</h3>
353<ul>
354<li><a href="../commands/npm.html">npm</a></li>
355<li><a href="../commands/npm-init.html">npm init</a></li>
356<li><a href="../configuring-npm/package-json.html">package.json</a></li>
357<li><a href="../using-npm/scripts.html">npm scripts</a></li>
358<li><a href="../commands/npm-publish.html">npm publish</a></li>
359<li><a href="../commands/npm-adduser.html">npm adduser</a></li>
360<li><a href="../using-npm/registry.html">npm registry</a></li>
361</ul></div>
362
363<footer id="edit">
364<a href="https://github.com/npm/cli/edit/latest/docs/lib/content/using-npm/developers.md">
365<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
366<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>
367</svg>
368Edit this page on GitHub
369</a>
370</footer>
371</section>
372
373
374
375</body></html>
codekingpro/portable-devtools · Team Ai