首頁  >  文章  >  web前端  >  nodeJS模組簡單用法

nodeJS模組簡單用法

不言
不言原創
2018-04-21 16:04:101332瀏覽

這篇文章主要介紹了nodeJS模組簡單用法,結合實例形式簡單分析了nodejs模組定義、引入、註冊、啟動等相關操作技巧,需要的朋友可以參考下

本文實例講述了nodeJS模組簡單用法。分享給大家參考,具體如下:

1.定義Student模組,Teacher模組

function add(student){
  console.log('Add Student:'+student);
}
exports.add=add;
function add(teacher){
  console.log('Add Teacher:'+teacher);
}
exports.add=add;

2.定義kclass模組

//引入student模块
var student=require('./student');
//引入teacher模块
var teacher=require('./teacher.js');
function add(teacherName,students){
 teacher.add(teacherName);
 students.forEach(function(item,index){
  student.add(item);
 });
}
//向模块对象,注册方法
exports.add=add;

3.定義啟動模組index.js

#
var class1=require('./kclass.js');
class1.add('高一班',['张三','李四']);

##執行結果:

相關推薦:

##詳解Nodejs模組載入運作原理


##

以上是nodeJS模組簡單用法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn