nodejs的模块化导入、导出:
导出:
第一种:module.exports.属性名 = 属性值 | module.exports = {属性名}(module是一个对象,有一个属性是exports)。
第二种:exports.属性名 = 属性值(exports是一个对象)。
导入:
第一种:let 集合名 = require('地址'); 集合名.属性名调用。
第二种:let {属性名} = require('地址')。
在nodejs环境中,每个模块都会包装成一个函数(方法)后运行的
console.log(arguments);(arguments 函数内置对象,来查看我们的方法体)
console.log(arguments.callee + ""); // function (exports, require, module, __filename, __dirname) {...}
exports:对象 导出
// console.log(module.exports === exports); //true
require:导入方法
__filename:返回当前模块的绝对路径
__dirname:返回当前模块所在的文件夹的绝对路径