path-ensure
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

path-ensure

Build Status node npm

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.
  • 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.
  • 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

Package Sidebar

Install

npm i path-ensure

Weekly Downloads

3

Version

2.0.1

License

MIT

Unpacked Size

5.39 kB

Total Files

5

Last publish

Collaborators

  • guntur