1. 程式人生 > 其它 >模組的匯入和匯出

模組的匯入和匯出

技術標籤:Node.jsnodejs

index1中有兩個函式。

function fn(){
    console.log('fn');
}

let student = {
username:"admin"
}

console.log('username',student.username);

// module.exports = {student,fn}   同時匯出兩個函式

exports.fn = fn;   //單獨匯出一個函式

index2中內容

let file1 = require('./index.js') //匯入檔案
console.log("f"
,file1); file1.fn() //執行函式

執行結果:
在這裡插入圖片描述