A Node.js library for creating temporary files and directories with automatic cleanup and flexible options.
Tmp is a Node.js library designed for creating temporary files and directories with built-in cleanup mechanisms. It solves the problem of managing short-lived storage in Node.js applications by providing secure, random naming and automatic removal options. The library supports both asynchronous and synchronous operations, making it versatile for different use cases.
Node.js developers who need to handle temporary files or directories in their applications, such as those building CLI tools, build scripts, or server-side processes that require ephemeral storage.
Developers choose Tmp for its simplicity, reliability, and comprehensive feature set, including automatic cleanup, customizable naming, and fine-grained control over file descriptors. It is a battle-tested library with wide adoption in the Node.js ecosystem.
Temporary file and directory creator for node.js
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offers both asynchronous (callback-based) and synchronous methods, as shown in the README with examples like `tmp.file()` and `tmp.fileSync()`, making it adaptable to various scripting and application needs.
Includes `setGracefulCleanup()` to automatically remove temporary files on process exit, reducing manual cleanup efforts and preventing disk clutter, demonstrated in the 'Graceful cleanup' section.
Supports prefixes, postfixes, templates (e.g., 'tmp-XXXXXX'), and custom directories via options like `dir` and `tmpdir`, allowing tailored temporary file paths for different use cases.
Provides `detachDescriptor` and `discardDescriptor` options for advanced control over file descriptors, enabling scenarios where descriptors need separate handling from file deletion, as detailed in the 'Controlling the Descriptor' section.
The README admits several breaking changes across versions, such as restrictions on `template` and `dir` options being relative to `tmpdir`, which can complicate upgrades and require code adjustments.
Asynchronous APIs are callback-based, and native promise support requires an additional package like `tmp-promise`, adding overhead for modern async/await workflows, as mentioned in the 'About' section.
The `dir` option requires that all directories in the specified path must exist, and tmp won't create them, leading to potential ENOENT errors without clear built-in recovery, as noted in the options description.