标签:集中 nbsp 组成 相对 ports nodejs 程序 path 编译
为了让NodeJS的文件可以相互调用,NodeJS提供了一个简单的模块系统。
模块是NodeJS应用程序的基本组成部分,文件和模块是一一对应的,换言之,一个NodeJS文件就是一个模块,这个文件可能是javascript代码,JSON或者编译过的C/C++扩展。
创建模块
// hello.js
exports.world = function(){
console.log(‘hello world‘);
}
// main.js
var hello = require(‘./hello‘);
hello.world();
require方法
require方法接受以下集中参数的传递
1、http、fs、path等,原生模块。
2、./mod或./mod,相对路径的文件模块。
3、/pathtomodule/mod,绝对路径的文件模块。
4、mod,非原生模块的文件模块。
标签:集中 nbsp 组成 相对 ports nodejs 程序 path 编译
原文地址:http://www.cnblogs.com/yzpweber/p/6569176.html