node.js写文件的目录? [英] node.js Write file with directories?
问题描述
如果使用fs.writeFile,我会得到:
错误:ENOENT,没有这样的文件或目录
我认为这是因为包含文件的目录不存在。
我应该首先使用fs.mkdir还是还有别的东西?
谢谢。
有人还没有使Perl的 File :: Path ,但这里至少有一个Node的递归创建器:
https://github.com/isaacs/npm/blob/master/lib/utils/mkdir-p.js
编辑:
这可能更易于使用: https:// github的.com / bpedro /节点-FS
If I use fs.writeFile I get:
Error: ENOENT, No such file or directory
I think that's because the directories that houses the file doesn't exist.
Am I supposed to use fs.mkdir first or is there something else?
Thanks.
Node.js lacks a recursive directory creator in the core API.
Someone is yet to make something equivalent to Perl's File::Path, but here's at least a recursive creator in Node:
https://github.com/isaacs/npm/blob/master/lib/utils/mkdir-p.js
Edit:
This is probably easier to use: https://github.com/bpedro/node-fs
这篇关于node.js写文件的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!