Node.js & module.exports & exports

https://www.cnblogs.com/xgqfrms/p/9493550.html

exports & module.exports

  1. Functions and objects are added to the root of a module by specifying additional properties on the special exports object.

module.exports & exports

CJS Modules


// CJS Modules /*
exports.a = 1;
exports.b = 2;
exports.c = 3;
exports.d = 4; // exports = { a: 1, b: 2, c: 3, d: 4 } */ exports.a = 1;
exports.b = 2;
module.exports = { c: 3 };
module.exports.d = 4; // module.exports = { c: 3, d: 4 }

结论

  1. exports just shorthand of module.exports

  2. if exist both exports & module.exports, module.exports will be overwritten exports

  3. best practice, just using module.exports as possible as you can


exports.a = 1;
exports.b = 2;
module.exports = { c: 3 };
module.exports.d = 4; // module.exports = { c: 3, d: 4 } console.log(module);


exports.a = 1;
exports.b = 2;
module.exports = { c: 3 };
module.exports.d = 4; // module.exports = { c: 3, d: 4 } module.exports.hello = true; // Exported from require of module
exports = { hello: false }; // Not exported, only available in the module console.log(`hello =`, exports);
console.log(module);

https://www.sitepoint.com/understanding-module-exports-exports-node-js#whatsthedifferencebetweenmoduleexportsandexports

https://www.hacksparrow.com/nodejs/exports-vs-module-exports.html

freecodecamp

https://www.freecodecamp.org/news/node-js-module-exports-vs-exports-ec7e254d63ac/

refs

https://www.w3schools.com/nodejs/nodejs_modules.asp



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


Node.js & module.exports & exports的更多相关文章

  1. (译)Node.js的模块-exports和module.exports

    原文标题:Node.js Module – exports vs module.exports 原文链接:http://www.hacksparrow.com/node-js-exports-vs-m ...

  2. (转)Node.js module.exports与exports

    本文转自Node.js module.exports与exports 作者: chemdemo 折腾Node.js有些日子了,下面将陆陆续续记录下使用Node.js的一些细节. 熟悉Node.js的童 ...

  3. node.js module.exports & exports & module.export all in one

    node.js module.exports & exports & module.export all in one cjs const log = console.log; log ...

  4. 创建并发布node.js module

      创建node.js module. 创建一个文件夹,用来存放module. Cd到新创建的文件夹,运行npm init,会提示输入package的信息. 可以按照这个视频的来输入.Test com ...

  5. Node.js & module system

    Node.js & module system Node.js v10.9.0 Documentation https://nodejs.org/api/modules.html#module ...

  6. 如何發佈一個完整Node.js Module

    本文會透過以下幾個段落,讓各位一步一步學習如何寫一個自已的Node.js Module並且發佈到npm package上 Node.js Module 結構 我們先建立一個 NodeModuleDem ...

  7. Node.js module.exports和exports的区别

    require 用来加载代码,而 exports 和 module.exports 则用来导出代码,从接触node.js就不会它们两陌生,上代码: foo.js exports.a = functio ...

  8. Node.js模块导出exports 和 module.exports 的区别

    原文: https://blog.csdn.net/Pwiling/article/details/51958693 每一个node.js执行文件,都自动创建一个module对象,同时,module对 ...

  9. node.js模块中exports和module.exports的区别

    Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一个文件里面定义的变量.函数.类,都是私有的,对其他文件不可见. CommonJS规范规定 ...

随机推荐

  1. CSP2020-S游记

    写在前面 Q:按照惯例是不是要写一片游记啊? A:好像是吧.. Q:都爆零了还有脸写游记? A:再不写今年就没机会了啊 Q:-- 我不要脸 Day -?? 某二区学长毒奶:去年三棵树,今年六张图 Da ...

  2. Java 学习之路 -- day00

    Java 学习之路 -- day00 Typora 快捷键操作 标题:#+空格 2. *斜体* 3. **加粗** 4. **斜体加粗*** 5. ~~删除线~~ 6. > 引用 7. ···分 ...

  3. ESRI,空间数据处理,WKT,GeoJson

    ESRI,空间数据处理,WKT,GeoJson 一.WKT 二.GeoJson 三.WKT转GeoJson 四.GeoJson 转 WKT 一.WKT WKT(well-known text)是一种文 ...

  4. MapReduce编程练习(三),按要求不同文件名输出结果

    问题:按要求文件名输出结果,比如这里我要求对一个输入文件中的WARN,INFO,ERROR,的信息项进行分析,并分别输入到对应的以WARN,INFO.ERROR和OTHER开头的结果文件中,其中结果文 ...

  5. codeblocks下载安装及快捷键

    100MB的下载链接:自带mingw  http://pan.baidu.com/s/1o6BgFP4  13.12版本  gcc 4.7.1的 这是windows版本的 linux下编译安装:参考: ...

  6. Memcached 缓存系统简介

    memcached官网:http://memcached.org/ What is Memcached? Memcached是一个自由开源的,高性能,高并发,分布式内存对象缓存系统. Memcache ...

  7. KVM虚拟化(KVM简介和KVM安装)

    KVM 虚拟化架构分类 寄居虚拟化架构:指在宿主操作系统之上安装和运行虚拟化程序,依赖于宿主操作系统对设备的支持和物理资源的管理. 裸金属虚拟化架构:指直接在硬件上面安装虚拟化软件,再在其上安装操作系 ...

  8. UML——交互图(序列图+协作图)

    交互图(interaction diagram):是协作图=通信图UML2.0以后的叫法=合作图=(Collaboration /Communication Diagram)以及序列图=顺序图=时序图 ...

  9. 力扣643.子数组最大平均数I-C语言实现

    题目 给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数. 示例: 输入:[1,12,-5,-6,50,3], k = 4 输出:12.75 解释:最大平均数 (12-5- ...

  10. 数据结构-kmp算法

    定义 改进字符串的匹配算法 关键:通过实现一个包含了模式串的局部匹配信息的next()函数,利用匹配失败的信息,减少匹配次数. 1.BF算法 暴力匹配 给定 文本串S "BBC ABCDAB ...