Node.js中的自定义模块
首先,是模块文件school.js
const students = [
'Lucas',
'Emily',
'Lucy',
'Martin'
];
const teachers = [
'Dr. Kerridge',
'Prof Johnson'
];
module.exports = { students, teachers };
在引用时,比如在index.js中
const { students, teachers } = require('./school.js');
使用Node.js自带模块
const os = require('os');