Harry
Harry

Reputation: 54949

node.js Write file with directories?

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.

Upvotes: 4

Views: 6774

Answers (1)

entropo
entropo

Reputation: 2481

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

Upvotes: 2

Related Questions