gpt4 book ai didi

node.js - NodeJS | Express - 从根目录导航回来

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:40 25 4
gpt4 key购买 nike

我的文件夹结构是:

项目→主页→testscenario.xml

data=fs.readFileSync("./testscenario.xml","utf8");

home 设置为root 文件夹。
目前,testscenario.xml 位于主文件夹中。

如果testscenario.xml位于项目文件夹中,我如何在express中向上导航一级来访问此文件?

最佳答案

“home 被设置为根文件夹。”

我把这句话的意思理解为你的.js文件在testscenario.xml同目录下

现在,如果testscenario.xml位于项目文件夹中

使用__dirname来处理路径:

data=fs.readFileSync(__dirname+"/../testscenario.xml","utf8");

关于node.js - NodeJS | Express - 从根目录导航回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52429139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com