@josh_stern/mktemp
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Temporary directories and files for NodeJS

License Coverage Size Version

Simple async wrapper for managing temporary directories and files.

Requirements

The distribution of this project targets ES2020 and makes use of fs.rm() which was added in NodeJS v14.14.0.

Installation

npm install @josh_stern/mktemp

Usage

Documentation Homepage

@josh_stern/mktemp does its best to choose reasonable defaults and relies on NodeJS modules as much as possible to maintain compatibility across systems. It uses fs.mkdtemp for generating unique directories in your system's temp folder (os.tmpdir()).

dir

Generate a unique temporary directory.

import {dir} from '@josh_stern/mktemp';
const myTempDir = await dir();
// Write files to myTempDir.path
await myTempDir.clean();

Options can be provided to add a prefix to the temp dir.

import {dir} from '@josh_stern/mktemp';
const myTempDir = await dir({prefix: 'my-dir'});
// myTempDir.path is now /var/folders/9a/0abc/T/my-dirSBv8Uk or the equivalent for your system
// ...
await myTempDir.clean();

file

Generates a unique directory and opens a file within.

import {file} from '@josh_stern/mktemp';
const myTempFile = await file();
await myTempFile.handle.writeFile('Hello for now!');
await myTempFile.clean();

Options can be provided to set the file name, mode, flags, etc.

import {file} from '@josh_stern/mktemp';
const myTempFile = await file({name: 'my-file', ext: '.txt'});
// myTempFile.path now ends in 'my-file.txt'
// ...
await myTempFile.clean();

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i @josh_stern/mktemp

    Weekly Downloads

    22

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    11.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • josh_stern