Ensure path exists
A simple module to generate the directory before writing the files. See fs-extra for advance.
$ npm install path-ensure
- Params:
- paths:
<string[]>- A sequence of path segments.
- paths:
- Return:
<Promise<string>> - Example:
const fs = require('fs'); const pathEnsure = require('path-ensure'); (async () => { const filepath = await pathEnsure(__dirname, 'some/path/to/create', 'unicorn.txt'); console.log(filepath); const writeStream = fs.createWriteStream(filepath); writeStream.write('🦄'); })();
- Params:
- paths:
<string[]>- A sequence of path segments.
- paths:
- Return:
<string> - Example:
const fs = require('fs'); const pathEnsure = require('path-ensure'); const writeStream = fs.createWriteStream( pathEnsure.sync('some/path/to/create', 'unicorn.txt') ); writeStream.write('🦄');
- make-dir - Make a directory and its parents if needed - Think
mkdir -p - fs-extra - Contains methods that aren't included in the vanilla Node.js fs package.
MIT © Guntur Poetra