創(chuàng)建模塊
新建一個(gè)文件, 比如我在src文件夾里創(chuàng)建一個(gè)greeting.js
const hello = () => {
console.log("hello~~!~");
}
module.exports.hello = hello
注意最后一句導(dǎo)出模塊里的內(nèi)容, 要用module.exports.xxx= xxx
調(diào)用模塊
我要在index.js里面調(diào)用剛剛創(chuàng)建的greeting模塊
const greeting = require('./src/greeting')
greeting.hello()
輸出hello~~!~