首页 > 代码库 > Node require

Node require

var user = require("./module_user");
//使用模块 module_user
console.log(user.userCount);
user.userLogout();
console.log(user.age);

 

module_user.js  //文件

var userCount = 98;
var userLogout = function(){
console.log("userLogout");
}
var age = 100;    //不会被输出 
//对外公开一些自己内部成员
exports.userCount = userCount;
exports.userLogout = userLogout;

function getSize(r){
return PI * r * r;
}

module.exports.size = getSize;

Node require