1 和app.js同一目录下添加新文件foo.js
2 exports方法
var PI = Math.PI; exports.area = function (r) { return PI * r * r; };
3 引用
//index.js /* * GET home page. */ var circle = require(‘../foo.js‘); exports.index = function (req, res) { var area = circle.area(5); console.log(area); res.render(‘index‘, { title: ‘Super Man‘ }); };
4 nodejs api http://nodejs.cn/api
原文:http://www.cnblogs.com/lihaozhou/p/4361377.html