Node.js系列教程 - 模块


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');

文章作者: 逻思
版权声明: 本博客所有文章除特別声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 逻思 !
  目录