node.js - export default 和 module.exports 有什么区别
问题描述
在 node.js 中,当我导出一个函数时,将它导入另一个文件的正确方法是什么?
https://nodejs.org/docs/latest-v9.x/api/
名称.js:
function Name(){}
module.exports = Name;
index.js:
const Name = require('./Name');
○
名称.js:
function Name(){}
export default Name;
index.js:
const Name = require('./Name');
正确的方法是什么?并按原样应用解构?
解决方案
Do the first one with module.exports. This is the node.js way to do it.
The second why is more of an ES6 / commonJS alternative.
Again do the first one.
推荐阅读
- javascript - 错误 message.guild.channels.filter 不是函数,使用 Discord.JS
- mongodb - 在`mongodb` Rust Lang 中找不到`options`
- asp.net-mvc - 我的引导表没有显示任何内容,甚至列
- ios - 在真实设备上运行 appium 测试时出现错误:xcodebuild failure: xcodebuild failed with code 65
- typescript - 所有属性都是字符串,一个属性是数字的接口
- regex - notepad++ 正则表达式替换匹配文本的内部序列
- docker - How to set Docker Desktop proxy settings from command line
- css - Is it true that different devices choose which convention to use for defining a pixel?
- rust - self behavior in Rust
- javascript - 使用 js 模板显示删除按钮