{"id":570,"date":"2025-12-07T09:54:51","date_gmt":"2025-12-07T01:54:51","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=570"},"modified":"2025-12-07T09:58:11","modified_gmt":"2025-12-07T01:58:11","slug":"node-js%e4%b8%adexports%e4%b8%8emodule-exports%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/07\/node-js%e4%b8%adexports%e4%b8%8emodule-exports%e5%8c%ba%e5%88%ab\/","title":{"rendered":"Node.js\u4e2dexports\u4e0emodule.exports\u533a\u522b"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd<strong>\u6700\u6e05\u6670\u3001\u6700\u5bb9\u6613\u8bb0\u4f4f\u7684\u300aNode.js \u4e2d exports \u4e0e module.exports \u7684\u533a\u522b\u300b\u603b\u7ed3<\/strong>\u3002\u8fd9\u662f\u9762\u8bd5\u3001\u9ad8\u7ea7\u5f00\u53d1\u5fc5\u8003\u5185\u5bb9\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 Node.js \u4e2d <code>exports<\/code> \u4e0e <code>module.exports<\/code> \u7684\u533a\u522b\uff08\u7ec8\u6781\u89e3\u91ca\uff09<\/h1>\n\n\n\n<p>\u5728 Node.js \u4e2d\uff0c\u6bcf\u4e2a\u6587\u4ef6\u90fd\u662f\u4e00\u4e2a\u6a21\u5757\uff0c\u6a21\u5757\u5bf9\u5916\u66b4\u9732\u5185\u5bb9\u4f9d\u8d56 <strong>module.exports<\/strong>\u3002<\/p>\n\n\n\n<p>\u800c <code>exports<\/code> \u53ea\u662f <code>module.exports<\/code> \u7684\u4e00\u4e2a <strong>\u5f15\u7528\uff08\u7b80\u5199\uff09<\/strong>\u3002<\/p>\n\n\n\n<p>\u7406\u89e3\u8fd9\u53e5\u8bdd\u5c31\u591f\u4e86\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>module.exports \u624d\u662f\u771f\u6b63\u7684\u5bfc\u51fa\u5bf9\u8c61\uff1b<br>exports \u53ea\u662f\u6307\u5411 module.exports \u7684\u4e00\u4e2a\u53d8\u91cf\u3002<br>\u4e00\u65e6\u4e24\u8005\u201c\u4e0d\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\u201d\uff0cexports \u5c31\u5931\u6548\u4e86\u3002<\/strong><\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e00\u3001\u6838\u5fc3\u539f\u7406\uff08\u4e00\u53e5\u8bdd\u89e3\u91ca\u6e05\u695a\uff09<\/h1>\n\n\n\n<p>Node.js \u52a0\u8f7d\u4e00\u4e2a\u6a21\u5757\u65f6\uff0c\u4f1a\u81ea\u52a8\u5305\u88c5\u6210\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n(function(exports, require, module, __filename, __dirname) {\n    \/\/ \u4f60\u7684\u4ee3\u7801\n});\n\n<\/pre><\/div>\n\n\n<p>\u8fdb\u5165\u51fd\u6570\u540e\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexports = module.exports;\n\n<\/pre><\/div>\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff1a<\/p>\n\n\n\n<p>\ud83d\udccc <strong>exports \u548c module.exports \u521d\u59cb\u65f6\u6307\u5411\u540c\u4e00\u4e2a\u7a7a\u5bf9\u8c61 <code>{}<\/code>\u3002<\/strong><br>\ud83d\udccc \u4f46\u6700\u7ec8\u771f\u6b63\u5bfc\u51fa\u7684\uff0c\u662f <code>module.exports<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e8c\u3001\u4ec0\u4e48\u65f6\u5019\u7528 <code>exports<\/code>\uff1f\uff08\u7b80\u5199\u5f62\u5f0f\uff09<\/h1>\n\n\n\n<p>\u9002\u7528\u4e8e\u9010\u4e2a\u6302\u8f7d\u5c5e\u6027\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexports.a = 1;\nexports.b = function () { };\n\n<\/pre><\/div>\n\n\n<p>\u7b49\u4ef7\u4e8e\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule.exports.a = 1;\nmodule.exports.b = function () { };\n\n<\/pre><\/div>\n\n\n<p>\u2714 \u53ea\u8981\u4f60 <strong>\u4e0d\u4fee\u6539 exports \u7684\u6307\u5411<\/strong>\uff0c\u5b83\u5c31\u80fd\u6b63\u786e\u5de5\u4f5c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e09\u3001\u4ec0\u4e48\u65f6\u5019 <code>exports<\/code> \u4f1a\u5931\u6548\uff1f\uff08\u9762\u8bd5\u5e38\u95ee\uff09<\/h1>\n\n\n\n<p>\u5f53\u4f60\u505a\u4e86\u201c\u91cd\u65b0\u8d4b\u503c\u201d\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexports = { a: 1 };\n\n<\/pre><\/div>\n\n\n<p>\u26a0 \u6b64\u65f6 <code>exports<\/code> \u4e0d\u518d\u7b49\u4e8e <code>module.exports<\/code>\uff0c\u53ea\u662f\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\u3002<br>\u771f\u6b63\u5bfc\u51fa\u7684\u4ecd\u7136\u662f\u539f\u6765\u7684 <code>module.exports<\/code>\u3002<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>exports \u4e0d\u80fd\u7528\u6765\u76f4\u63a5\u8d4b\u503c\u5bf9\u8c61\uff0c\u53ea\u80fd\u6dfb\u52a0\u5c5e\u6027\u3002<\/strong><\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u56db\u3001\u6b63\u786e\u5bfc\u51fa\u5bf9\u8c61\u7684\u552f\u4e00\u65b9\u5f0f<\/h1>\n\n\n\n<p>\u5982\u679c\u4f60\u8981\u5bfc\u51fa\u4e00\u4e2a\u5bf9\u8c61\u3001\u7c7b\u3001\u51fd\u6570\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule.exports = {\n  a: 1,\n  b() {}\n};\n\n<\/pre><\/div>\n\n\n<p>\u6216\u8005\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule.exports = function() {};\n\n<\/pre><\/div>\n\n\n<p>\u5fc5\u987b\u7528 <code>module.exports<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e94\u3001\u5e38\u89c1\u9519\u8bef\u793a\u4f8b\uff08\u4e00\u5b9a\u8981\u907f\u514d\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u274c \u9519\u8bef\uff1a\u60f3\u5bfc\u51fa\u5bf9\u8c61\u5374\u7528 exports \u8d4b\u503c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexports = {\n  a: 1\n};\n\n<\/pre><\/div>\n\n\n<p>\u7ed3\u679c\u7528\u6237 require \u540e\u5f97\u5230\u7684\u662f\uff1a<code>{}<\/code><\/p>\n\n\n\n<p>\u56e0\u4e3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Node.js \u5bfc\u51fa\u7684\u662f <code>module.exports<\/code><\/li>\n\n\n\n<li>\u4f60\u6539\u7684\u662f <code>exports<\/code> \u7684\u5f15\u7528<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u516d\u3001\u6b63\u786e\u793a\u4f8b\u603b\u7ed3<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5bfc\u51fa\u591a\u4e2a\u5c5e\u6027 \u2192 \u7528 exports \u6216 module.exports \u90fd\u884c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexports.a = 1\nexports.b = 2\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5bfc\u51fa\u6574\u4e2a\u5bf9\u8c61 \u2192 \u5fc5\u987b\u7528 module.exports<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule.exports = { a: 1, b: 2 }\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5bfc\u51fa\u4e00\u4e2a\u51fd\u6570 \u2192 \u5fc5\u987b\u7528 module.exports<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmodule.exports = function() {}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e03\u3001\u7ec8\u6781\u8bb0\u5fc6\u53e3\u8bc0<\/h1>\n\n\n\n<p>\ud83d\udccc <strong>exports \u662f module.exports \u7684\u201c\u5f15\u7528\u201d<\/strong><br>\ud83d\udccc <strong>\u6700\u7ec8\u5bfc\u51fa\u7684\u662f module.exports<\/strong><br>\ud83d\udccc <strong>\u4e0d\u8981\u7528 exports = &#8230;\uff0c\u8981\u7528 module.exports = &#8230;<\/strong><\/p>\n\n\n\n<p>\u518d\u603b\u7ed3\u4e00\u53e5\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u6dfb\u52a0\u5c5e\u6027\u7528 exports\uff0c\u66ff\u6362\u5bf9\u8c61\u7528 module.exports<\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd\u6700\u6e05\u6670\u3001\u6700\u5bb9\u6613\u8bb0\u4f4f\u7684\u300aNode.js \u4e2d exports \u4e0e mod&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/07\/node-js%e4%b8%adexports%e4%b8%8emodule-exports%e5%8c%ba%e5%88%ab\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-javascript"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=570"}],"version-history":[{"count":2,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":572,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/570\/revisions\/572"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}