node.js - Express Router如何获取全局设置
PHPz
PHPz 2017-04-17 14:50:43
0
1
775

**在app中设置了一个配置,加了一个router,如何在router中获取这个设置

在app.js中
  var users = require('./routes/users');
  app.set('upload', path.join(__dirname, 'public/upload'));
  app.use('/users', users);
在./routes/users文件中
    var express = require('express');
    var router = express.Router();
    router.post('/upload', function(req, res, next) {
        //向将上传的文件保存到目录public/upload,如何获得在app.js文件中upload这个设置?
          var upload = app.get('upload');
    });
    
    module.exports = router;**
PHPz
PHPz

学习是最好的投资!

reply all(1)
伊谢尔伦

You can get it like this

var upload = req.app.get('upload');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template