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);
本文来自博客园,作者:tinyphp,转载请注明原文链接:https://www.cnblogs.com/tinyphp/p/4931907.html
向着星辰与深渊,博客园加油