{"id":288,"date":"2023-12-12T11:26:49","date_gmt":"2023-12-12T03:26:49","guid":{"rendered":"http:\/\/ericw.top\/?p=288"},"modified":"2024-01-02T09:35:29","modified_gmt":"2024-01-02T01:35:29","slug":"path%e6%a8%a1%e5%9d%97-%e8%b7%af%e5%be%84%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=288","title":{"rendered":"Path\u6a21\u5757 &#8211; \u8def\u5f84\u5904\u7406"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"toc-0\">Path\u6a21\u5757 - \u8def\u5f84\u5904\u7406<\/h1>\n\n\n\n<p><em>\u95ee\u9898\uff1aNode.js\u4ee3\u7801\u4e2d\uff0c\u76f8\u5bf9\u8def\u5f84\u662f\u6839\u636e<strong>\u7ec8\u7aef\u6240\u5728\u8def\u5f84<\/strong>\u6765\u67e5\u627e\u7684\uff0c\u53ef\u80fd\u65e0\u6cd5\u627e\u5230\u4f60\u7684\u6587\u4ef6<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"897\" height=\"270\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349566727.png\" alt=\"\" class=\"wp-image-289\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349566727.png 897w, http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349566727-300x90.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349566727-768x231.png 768w\" sizes=\"(max-width: 897px) 100vw, 897px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"958\" height=\"249\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349550792.png\" alt=\"\" class=\"wp-image-290\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349550792.png 958w, http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349550792-300x78.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702349550792-768x200.png 768w\" sizes=\"(max-width: 958px) 100vw, 958px\" \/><\/figure>\n\n\n\n<p><em>\u8fd9\u4e2a\u62a5\u9519\u7684\u610f\u601d\u662f\uff0c\u6ca1\u6709\u627e\u5230\u76ee\u6807\u6587\u4ef6\uff08<strong>\u56e0\u4e3anode.js\u7684\u6587\u4ef6\u8def\u5f84\u662f\u4ee5\u7ec8\u7aef\u6240\u5728\u6587\u4ef6\u8def\u5f84\u5bfb\u627e\u7684<\/strong>\uff09<\/em><\/p>\n\n\n\n<p>\u89e3\u51b3\u95ee\u9898\uff1a<\/p>\n\n\n\n<p><strong>\u5efa\u8bae<\/strong>\uff1a\u5728Node.js\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<\/p>\n\n\n\n<p><strong>\u8865\u5145<\/strong>\uff1a<code class=\"prettyprint\" >__dirname<\/code>  \u5185\u7f6e\u53d8\u91cf\uff08\u83b7\u53d6\u5f53\u524d\u6a21\u5757\u76ee\u6807\u7684-\u7edd\u5bf9\u8def\u5f84\uff09<\/p>\n\n\n\n<ul>\n<li>windows\uff1a<code class=\"prettyprint\" >D:\\\u5907\u8bfe\u4ee3\u78013-B\u7ad9\u8bfe\u7a0b\\03Node.js\u4e0eWebpack\\03-code\\03<\/code><\/li>\n\n\n\n<li>mac\uff1a<code class=\"prettyprint\" >\/Users.\/xx\/Desktop\/\u5907\u8bfe\u4ee3\u7801\/3-B\u7ad9\u8bfe\u7a0b\/03_Node.js-\u4e0eWebpack.\/03-code\/03<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a<code class=\"prettyprint\" >Path.join()<\/code>\u4f1a\u4f7f\u7528\u7279\u5b9a\u7684\u5e73\u53f0\u5206\u5272\u7ebf\uff0c\u4f5c\u4e3a\u5b9a\u754c\u7b26\uff0c\u5c06\u6240\u6709\u7ed9\u5b9a\u7684\u8def\u5f84\u7247\u6bb5\u8fde\u63a5\u5728\u4e00\u8d77<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >Path.join(&#039;03&#039;,&#039;dist\/js&#039;,&#039;index.js&#039;)\n\/\/windows:&#039;03\\dist\\js\\index.js&#039;\n\/\/mac:&#039;03\\dist\\js\\index.js&#039;<\/code><\/pre>\n\n\n\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<ol>\n<li>\u52a0\u8f7dpath\u6a21\u5757<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const path = require(&#039;path&#039;)<\/code><\/pre>\n\n\n\n<ol>\n<li>\u4f7f\u7528path.join\u65b9\u6cd5\u62fc\u63a5\u8def\u5f84<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >path.join(&#039;\u8def\u5f841&#039;,&#039;\u8def\u5f842&#039;,&#039;...&#039;)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Path\u6a21\u5757 &#8211; \u8def\u5f84\u5904\u7406 \u95ee\u9898\uff1aNode.js\u4ee3\u7801\u4e2d\uff0c\u76f8\u5bf9\u8def\u5f84\u662f\u6839\u636e\u7ec8\u7aef\u6240\u5728\u8def\u5f84\u6765\u67e5\u627e\u7684\uff0c\u53ef\u80fd\u65e0\u6cd5\u627e\u5230\u4f60\u7684\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/288"}],"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=288"}],"version-history":[{"count":2,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":602,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions\/602"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/289"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}