【发布时间】:2019-10-19 14:15:05
【问题描述】:
我正在尝试从项目目录之外运行我的 index.js 脚本。我的项目结构如下:
app
- config
- config.js
- public
- index.html
- src
- index.js
现在当我从我的应用程序文件夹之外运行我的 src/index.js 时,require() 能够解析相对路径
const config = require(`../config/config`);
另一方面,express.static 无法解析此类相对路径。
e.g. app.use(express.static("../public"));
为什么我需要使用 path.join 并获取绝对路径?
【问题讨论】:
标签: node.js express node-modules