node.js创建并引用模块

app.js

var express = require('express');
var app = express();
var con = require('./content');
con.hello();

app.listen(3000);

模块content.js

exports.hello=function(){
    console.log("hello world");
}

 

 

 

扩展性更好点的,把模块做成对象

模块content.js

var content={};
content.hello=function(){
    console.log("Hello tinyphp");
}
exports.mycon=content;

app.js引入模块

var express = require('express');
var app = express();
var con = require('./content');
con.mycon.hello();

app.listen(3000);

 

posted @ 2015-11-02 23:23  tinyphp  Views(549)  Comments(0Edit  收藏  举报