UNPKG

@augment-vir/node

Version:

A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.

15 lines (14 loc) 505 B
import { mkdir, writeFile } from 'node:fs/promises'; import { dirname } from 'node:path'; /** * Writes to the given file path and always ensures that the path's parent directories are all * created. * * @category Node : File * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export async function writeFileAndDir(path, contents) { await mkdir(dirname(path), { recursive: true }); await writeFile(path, contents); }