是否有一种不使用../../../来访问根目录的方法?下面的代码工作正常,但只是认为我访问公用文件夹的方式有点混乱。
router.get('/', function(req, res) {
res.sendFile('index.html', { root: path.join(__dirname, '../../public') });
});应用结构:
/app
--node-modules
--public
--app //contains all angularjs related files
--assets //contains images and js libraries
--index.html
--server
--routes
--index.js //this holds all the route related code发布于 2015-12-09 11:16:37
途中是使用应用根路径。它是一个模块,可以帮助您从应用程序中的任何位置访问应用程序的根路径,而无需求助于相对路径。
var appRoot = require('app-root-path');
router.get('/', function(req, res) {
res.sendFile('index.html', { root: path.join(__dirname, appRoot + '/public') });
});https://stackoverflow.com/questions/34173686
复制相似问题