【发布时间】:2015-04-19 20:59:27
【问题描述】:
尝试使用 fs.writeFile 将文件写入同级目录。当在同一目录中使用Sitemap.xml 时,这可以正常工作,但不能使用相对路径。 public 目录存在,无论Sitemap.xml 是否存在,都会报同样的错误。
相关目录结构:
/public
Sitemap.xml
app files
/create-sitemap
index.js - file containing code below
app.js
fs.write('../public/Sitemap.xml', data.toString(), function(err) {
if (err) throw err;
console.log("Wrote sitemap to XML");
});
Toms-MacBook-Pro:moviehunter tomchambers$ node create-sitemap/index.js
/Users/tomchambers/projects/project/create-sitemap/index.js:88
if (err) throw err;
^
Error: ENOENT, open '../public/Sitemap.xml'
【问题讨论】:
-
你的项目文件夹结构是什么样的?