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