Helper functions for node fs.
npm add m-fs
import * as mfs from 'm-fs';
Calls fs.promises.readFile
.
Calls fs.promises.writeFile
. This method also makes ensure the target directory is created before writing the file.
Calls fs.promises.stat
.
Like statAsync
, but instead of throwing an error, it returns null
in that case.
Returns true
if the given path/directory/file exists.
await subPaths('./data/docs');
// ['backup', 'resume.pdf', 'readme.md']
await subPathsWithType('./data/docs');
// [{ path: 'backup', isFile: false }, { path: 'resume.pdf', isFile: true }, { path: 'readme.md', isFile: true }]
await subDirs('./data/docs');
// ['backup']
await subFiles('./data/docs');
// ['resume.pdf', 'readme.md']
Calls fs.promises.mkdir
with { recursive: true }
.