{"id":348,"date":"2023-12-13T11:28:13","date_gmt":"2023-12-13T03:28:13","guid":{"rendered":"http:\/\/ericw.top\/?p=348"},"modified":"2023-12-13T11:28:13","modified_gmt":"2023-12-13T03:28:13","slug":"npm-%e8%bd%af%e4%bb%b6%e5%8c%85%e7%ae%a1%e7%90%86%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=348","title":{"rendered":"npm \u8f6f\u4ef6\u5305\u7ba1\u7406\u5de5\u5177"},"content":{"rendered":"<h1 id=\"toc-0\">npm \u8f6f\u4ef6\u5305\u7ba1\u7406\u5de5\u5177<\/h1>\n<p><strong>npm\uff0c\u5168\u540d node package manger\u3002<\/strong><\/p>\n<p><strong>npm \u662f Node.js \u5b98\u65b9\u63d0\u4f9b\u7684\u5305\u7ba1\u7406\u5de5\u5177<\/strong>\uff0c\u4ed6\u5df2\u7ecf\u6210\u4e86 Node.js \u5305\u7684<strong>\u6807\u51c6\u53d1\u5e03\u5e73\u53f0<\/strong>\uff0c<strong>\u7528\u4e8enode\u63d2\u4ef6\u7ba1\u7406\uff08\u5305\u62ec\u5b89\u88c5\u3001\u5378\u8f7d\u3001\u7ba1\u7406\u4f9d\u8d56\u7b49\uff09<\/strong>\u3002npm \u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f7f\u4f60\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e0b\u8f7d\u3001\u5b89\u88c5\u3001\u5347\u7ea7\u3001\u5220\u9664\u5305\uff0c\u4e5f\u53ef\u4ee5\u8ba9\u4f60\u4f5c\u4e3a\u5f00\u53d1\u8005\u53d1\u5e03\u5e76\u7ef4\u62a4\u5305\u3002<\/p>\n<p>\u57282017\u5e741\u6708\u65f6\uff0cpm\u4ed3\u5e93\u4e2d\u5c31\u5df2\u6709\u8d85\u8fc7<strong>350000\u4e2a\u8f6f\u4ef6\u5305<\/strong>\uff0c\u8fd9\u4f7f\u5176\u6210\u4e3a\u4e16\u754c\u4e0a<strong>\u6700\u5927\u7684\u5355\u4e00\u8bed\u8a00\u4ee3\u7801\u4ed3<\/strong><br \/>\n<strong>\u5e93<\/strong>\uff0c\u5e76\u4e14\u53ef\u4ee5\u786e\u5b9a\u51e0\u4e4e\u6709\u53ef\u7528\u4e8e\u4e00\u5207\u7684\u8f6f\u4ef6\u5305\u3002<\/p>\n<p>\u5b83\u8d77\u521d\u662f\u4f5c\u4e3a<strong>\u4e0b\u8f7d\u548c\u7ba1\u7406Node.js\u5305\u4f9d\u8d56\u7684\u65b9\u5f0f<\/strong>\uff0c\u4f46\u5176\u73b0\u5728\u4e5f\u5df2\u6210\u4e3a<strong>\u524d\u7aefJavaScript\u4e2d\u4f7f\u7528\u7684\u5de5\u5177<\/strong>\u3002<\/p>\n<ul>\n<li>npm \u662f<code class=\"prettyprint\" >Node<\/code>\u7684\u5f00\u653e\u5f0f\u6a21\u5757\u767b\u8bb0\u548c\u7ba1\u7406\u7cfb\u7edf\uff0c\u662f<code class=\"prettyprint\" >Node.js<\/code>\u5305\u7684\u6807\u51c6\u53d1\u5e03\u5e73\u53f0\uff0c\u7528\u4e8e<code class=\"prettyprint\" >Node.js<\/code>\u5305\u7684\u53d1\u5e03\u3001\u4f20\u64ad\u3001\u4f9d\u8d56\u63a7\u5236\uff0c\u7f51\u5740\uff1a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.npmjs.com\/\">https:\/\/www.npmjs.com\/<\/a><\/li>\n<li>npm \u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e0b\u8f7d\u3001\u5b89\u88c5\u3001\u5347\u7ea7\u3001\u5220\u9664\u5305\uff0c\u4e5f\u53ef\u4ee5\u8ba9\u4f60\u4f5c\u4e3a\u5f00\u53d1\u8005\u53d1\u5e03\u5e76\u7ef4\u62a4\u5305<\/li>\n<\/ul>\n<h2 id=\"toc-1\">npm \u5982\u4f55\u4f7f\u7528<\/h2>\n<ul>\n<li>npm \u5728\u6309\u7167 Node.js \u65f6\u4f1a\u8fde\u5e26\u88ab\u5b89\u88c5\u3002\u4f46\u6709\u53ef\u80fd\u4e0d\u662f\u6700\u65b0\u7248\u672c\uff0c\u9700\u8981 <code class=\"prettyprint\" >npm install npm@latest -g<\/code> \u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c\u3002<\/li>\n<\/ul>\n<p>\u57fa\u672c\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-js\"># \u67e5\u770b npm \u547d\u4ee4\u5217\u8868\n$ npm help\n\n# \u67e5\u770b\u5404\u4e2a\u547d\u4ee4\u7684\u7b80\u5355\u7528\u6cd5\n$ npm -l\n\n# \u67e5\u770b npm \u7684\u7248\u672c\n$ npm -v\n\n# \u67e5\u770b npm \u7684\u914d\u7f6e\n$ npm config list -l<\/code><\/pre>\n<h2 id=\"toc-2\">npm \u7684\u4f7f\u7528<\/h2>\n<ol>\n<li><strong>\u521d\u59cb\u5316\u6e05\u5355\u6587\u4ef6\uff1a<code class=\"prettyprint\" >npm init -y<\/code> \uff08\u5f97\u5230package.json\u6587\u4ef6\uff0c\u6709\u5219\u7565\u8fc7\u6b64\u547d\u4ee4\uff09<\/strong><\/li>\n<li><strong>\u4e0b\u8f7d\u8f6f\u4ef6\u5305  \uff1a<code class=\"prettyprint\" >npm i \u8f6f\u4ef6\u5305\u540d\u79f0<\/code><\/strong><\/li>\n<li><strong>\u4f7f\u7528\u8f6f\u4ef6\u5305<\/strong><\/li>\n<\/ol>\n<p><strong>\u9700\u6c42\uff1a<\/strong>\u4f7f\u7528dayjs\u8f6f\u4ef6\u5305\uff0c\u6765\u683c\u5f0f\u5316\u6587\u4ef6<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702437296093-300x125.png\" alt=\"\" \/><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p>\u521d\u59cb\u5316\u6e05\u5355\u6587\u4ef6 <code class=\"prettyprint\" >npm init -y<\/code><\/p>\n<\/li>\n<li>\n<p>\u4e0b\u8f7d\u8f6f\u4ef6\u5305  \uff08<code class=\"prettyprint\" >npm i dayjs<\/code>\uff09<\/p>\n<p>\u4f1a\u81ea\u52a8\u628a\u8f6f\u4ef6\u5305\u6e90\u7801\u653e\u5230node_modules\u4e2d<\/p>\n<p>npm\u4f1a\u8bb0\u5f55\u5230 package.json \u5e76\u56fa\u5316\u7248\u672c<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u4f7f\u7528<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/**\n * \u76ee\u6807\uff1a\u4f7f\u7528 npm \u4e0b\u8f7d dayjs \u8f6f\u4ef6\u5305\u6765\u683c\u5f0f\u5316\u65e5\u671f\u65f6\u95f4\n *  1. \uff08\u53ef\u9009\uff09\u521d\u59cb\u5316\u9879\u76ee\u6e05\u5355\u6587\u4ef6\uff0c\u547d\u4ee4\uff1anpm init -y\n *  2. \u4e0b\u8f7d\u8f6f\u4ef6\u5305\u5230\u5f53\u524d\u9879\u76ee\uff0c\u547d\u4ee4\uff1anpm i \u8f6f\u4ef6\u5305\u540d\u79f0\n *  3. \u4f7f\u7528\u8f6f\u4ef6\u5305\n *\/\n\/\/ 3. \u4f7f\u7528\u8f6f\u4ef6\u5305\nconst dayjs = require(&#039;dayjs&#039;)\nconst nowDateStr = dayjs().format(&#039;YYYY-MM-DD&#039;)\nconsole.log(nowDateStr)<\/code><\/pre>\n<h2 id=\"toc-3\">npm \u5b89\u88c5\u6240\u6709\u4f9d\u8d56<\/h2>\n<p><strong>\u4f8b\uff1a<\/strong>\u6211\u4eec\u7528\u5176\u4ed6\u4eba\u7684\u9879\u76ee\uff0c\u4f46\u662f\u7f3a\u5c11\u4e86node_modules\u6587\u4ef6\uff08\u91cc\u9762\u5b58\u653e\u7684\u8f6f\u4ef6\u5305\uff09\uff0c\u56e0\u4e3a\u7f3a\u5c11\u8f6f\u4ef6\u5305\uff0c\u9879\u76ee\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c<\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><code class=\"prettyprint\" >npm i<\/code>    <strong>\uff08\u4e0b\u8f7dpackage.json\u4e2d\u8bb0\u5f55\u7684\u6240\u6709\u8f6f\u4ef6\u5305\uff09<\/strong><\/p>\n<h2 id=\"toc-4\">npm - \u5168\u5c40\u8f6f\u4ef6\u5305 nodemon<\/h2>\n<p><strong>\u8f6f\u4ef6\u5305\u533a\u522b\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u672c\u5730\u8f6f\u4ef6\u5305\uff1a<\/strong>\u5f53\u524d\u9879\u76ee\u5185\u4f7f\u7528\uff0c\u5c01\u88c5\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5b58\u5728\u4e8enode_modules\u3002<\/li>\n<li><strong>\u5168\u5c40\u8f6f\u4ef6\u5305\uff1a<\/strong>\u672c\u673a\u6240\u6709\u9879\u76ee\u4f7f\u7528\uff0c\u5c01\u88c5\u7684\u547d\u4ee4\u548c\u5de5\u5177\uff0c\u5b58\u5728\u4e8e\u7cfb\u7edf\u8bbe\u7f6e\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong><code class=\"prettyprint\" >nodemon<\/code>\uff1a\u66ff\u4ee3node\u547d\u4ee4\uff0c\u68c0\u6d4b\u4ee3\u7801\u66f4\u6539\uff0c\u81ea\u52a8\u91cd\u65b0\u542f\u52a8<\/strong><\/p>\n<p><strong>\u4f7f\u7528\uff1a<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5 \uff1a<code class=\"prettyprint\" >npm i nodemon -g<\/code>\uff08\u4ee3\u8868\u5b89\u88c5\u5230\u5168\u5c40\u73af\u5883\u4e2d\uff09<\/li>\n<li>\u8fd0\u884c\uff1a<code class=\"prettyprint\" >nodemon \u5f85\u6267\u884c\u7684\u76ee\u6807js\u6587\u4ef6<\/code> <\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>npm \u8f6f\u4ef6\u5305\u7ba1\u7406\u5de5\u5177 npm\uff0c\u5168\u540d node package manger\u3002 npm \u662f Node.js \u5b98 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,11,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/348"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions"}],"predecessor-version":[{"id":350,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions\/350"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/349"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}