Skip to content

iguntur/path-ensure

Repository files navigation

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