tmp-promise

A promise-based wrapper around the tmp package for creating and cleaning up temporary files and directories with async/await.

Library
npm
v3.0.3
134 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
35 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 60
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
63 /100 Good
Architecture 65
Code Quality 65
Innovation 78
Learning Curve 45

tmp-promise wraps the widely used tmp library in a promise-based API, so temporary file and directory workflows can be written with async/await instead of Node-style callbacks. It preserves the underlying package’s behavior — random name generation via crypto with a pseudo-random fallback, configurable prefixes/postfixes/templates, and automatic cleanup on process exit — while adding a small set of ergonomic wrappers.

Beyond the direct file()/dir()/tmpName() promise wrappers, it also exposes withFile() and withDir() disposer-style helpers that create a temporary resource, hand it to a callback, and guarantee cleanup once that callback’s returned promise settles, whether it resolves or rejects. Synchronous variants (fileSync, dirSync, tmpNameSync) are re-exported directly from tmp for callers that don’t need promises.

What You Get

  • Promise-returning file() and dir() functions that resolve with a path (and file descriptor for files) plus a cleanup() function
  • withFile() and withDir() disposer helpers that automatically clean up the temp resource once your async callback settles, even on error
  • Promise-wrapped tmpName() for generating a unique temporary filename without creating the file
  • Re-exported synchronous APIs (fileSync, dirSync, tmpNameSync, setGracefulCleanup) for callers that don’t need promises
  • Full TypeScript typings (index.d.ts) for FileResult, DirectoryResult, and all exported functions

Common Use Cases

  • Writing a test that needs a scratch file or directory and wants guaranteed cleanup via withFile/withDir even if an assertion throws
  • Downloading or generating a file to a temp path inside an async function before uploading or processing it further
  • Building a CLI or build tool that needs a disposable working directory for intermediate build artifacts
  • Replacing callback-based tmp usage in a codebase that has migrated to async/await

Under The Hood

Architecture The whole library is a single file, index.js (about 50 lines), that wraps the tmp package’s callback-based API using Node’s util.promisify, exposing file, dir, and tmpName as promise-returning functions, plus two additional composed helpers, withFile and withDir, that implement the disposer pattern via try/finally. There is no internal module structure beyond that one file — it is a thin adapter layer with no state of its own, delegating all real temp-file logic (random name generation, entropy fallback, process-exit cleanup) to the tmp dependency; changing the core abstraction here effectively means changing the shape of the promisify-based wrapper functions or the version of tmp being wrapped.

Tech Stack A plain CommonJS module targeting Node.js 8+, with a single runtime dependency, tmp (^0.2.0), and dev dependencies of @types/tmp, mocha (7.1.2) for the test suite, and tsd (0.25.0) for type-testing index.d.ts against index.test-d.ts. There is no build step — package.json’s files field ships index.js and index.d.ts directly, with no bundler or transpiler involved. CI runs on CircleCI, executing the Mocha suite and the tsd type check across Node 14, 16, 18, and 19 on every commit.

Code Quality A single test.js file uses Mocha’s BDD interface (describe/context/it) with Node’s built-in assert module, covering file(), dir(), withFile(), and withDir() — including a happy path, a custom-prefix case, and an explicit error-propagation test against a nonexistent directory. No linter or formatter configuration is present in the repo, and there is no explicit error-handling logic beyond letting tmp’s callback errors propagate through promisify. Type safety comes from the hand-written index.d.ts, exercised by tsd against index.test-d.ts, rather than the implementation itself being written in TypeScript.

API Design The public API mirrors the wrapped tmp package’s naming closely (file, dir, tmpName, and their Sync variants), which keeps the migration path from callback-based tmp usage nearly frictionless and adds only two new concepts, withFile and withDir, rather than a whole new vocabulary. Getting started requires zero configuration since file() and dir() work with no options, and the README documents every option inherited from tmp (mode, prefix, postfix, template, dir, tries, keep, unsafeCleanup) directly. TypeScript users get typed results (FileResult, DirectoryResult) out of the box via the bundled index.d.ts, though users unfamiliar with the underlying tmp package may still need to cross-reference its docs for less common options.

Used by 6 apps in this directory

TypeScript
95%
AGPL 3.0

Docmost

CMS · Collaboration · Note Taking

21,801

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
69
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,787

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 75%
Updated 4 days ago
Rust
65%
Other

GitButler

AI Development · Developer Tools · Devops

21,726

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
66
Dependency
Built with
Rust 65%
TypeScript 22%
Svelte 10%
Updated 4 days ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,875

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
66
Dependency
Built with
TypeScript 83%
Python 11%
Updated 5 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

206,147

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 92%
Updated 4 days ago
Rust
98%
GPL 3.0

Pake

Developer Tools

61,763

Turn any webpage into a lightweight native desktop app with one command — built on Rust/Tauri instead of Electron, producing installers nearly 20x smaller (typically under 10MB) for macOS, Windows, and Linux.

View details
92
Repo Health
75
Technical
73
Dependency
Built with
Rust 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers