path-ensure
v2.0.1
Published
Ensure path exists
Downloads
23
Maintainers
Readme
path-ensure
Ensure path exists
A simple module to generate the directory before writing the files. See fs-extra
for advance.
Install
$ npm install path-ensure
API
pathEnsure([...paths])
- 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('🦄'); })();
.sync([...paths])
- 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('🦄');
Related
- 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.
License
MIT © Guntur Poetra