talira

tmp (Node.js)

Temporary file and directory creator for Node.js

open sourceMITfree

tmp creates temporary files and directories in Node.js, with asynchronous and synchronous APIs whose parameters are all optional. It picks random names with crypto, or a six-letter random identifier when you give a template, and can remove the files when the process exits. You can also point it at a temporary directory other than the system's. A promise-based wrapper, tmp-promise, is a separate package.

Problems it solves

  • create a temporary file in Node.js that's cleaned up when the process exits
  • make a unique temporary directory for a test in Node.js
  • get a safe random temp file name without collisions

Features

  • temporary files and directories, async and sync APIs
  • random names from crypto, or templates with a six-letter random identifier
  • optional removal on process exit
  • a custom temporary directory instead of the system one

Limitations

  • Needs Node.js 14.14 or newer.1

Alternatives

The same job

These do what tmp (Node.js) does.

  1. rimraf rm -rf for Node.js, cross-platform
  2. del Delete files and directories by glob in Node.js, with a promise API
  3. fs-extra Node.js fs with recursive mkdir, copy, remove and promises

Compare tmp (Node.js) with the top 3