我用了webstorm新建一个项目,然后:
app.js
app.locals.title = '123’; (不要这个) app.set(‘xxxx’,’xxxxxxxxxxxx’)
routers/index.js
var express = require(‘express’); var router = express.Router(); var app = require(‘…/app’); console.log(1,app.get('xxxx)); —> 没有get方法 /* GET home page. */ router.get('/’, function(req, res) { res.render('index’, { title: ‘Express’ }); });
module.exports = router;
16 回复
其实我推荐的的写法是 conf.js var conf = {} conf.title = ‘xxx’
router/index require(‘…/conf.js’) console.log(conf.title)
//其实说到底,直接用require,不需要exports。
@coolicer app.js app.use(router(app))
router var app; module.exports = paser; var paser = function(appx){ app = appx; router; }
按照这个思路改改