tmp
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
rimraf | 3.0.2 | 6.33 kB | ISC | prod |
Tmp is an easy-to-use and efficient library for creating temporary files and directories in a Node.js environment. The package offers both asynchronous and synchronous API and maintains compatibility with promisified versions of the API as seen in tmp-promise. Notably, Tmp uses crypto libraries for random file name generation to assure file uniqueness, hence reducing conflict chances. It provides the flexibility of choosing to remove the temporary file on process exit or not, and the options to override the standard OS temporary directory for storing your temporary directories and files.
Tmp package is used by installing it from npm by running npm install tmp
. Once installed, you can import it in your Javascript file using const tmp = require('tmp');
. To create a temporary file asynchronously, for instance, you would use:
const tmp = require('tmp');
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
if (err) throw err;
console.log('File: ', path);
console.log('Filedescriptor: ', fd);
cleanupCallback();
});
Or synchronously:
const tmp = require('tmp');
const tmpobj = tmp.fileSync();
console.log('File: ', tmpobj.name);
console.log('Filedescriptor: ', tmpobj.fd);
tmpobj.removeCallback();
Tmp provides countless more functionalities beyond just creating temporary files including temporary directory creation, filename generation, and more with both synchronous and asynchronous implementations, offering flexibility and power in managing temporary files and directories in Node.js.
The Tmp package offers comprehensive and elaborate documentation, including in-depth usage examples and advanced features on the dedicated Tmp documentation page. The documentation provides clear guidelines on the installation and usage of the package, option configurations, and the usage of the API available on the Tmp library. Whether you're a beginner or a seasoned developer, every aspect of Tmp for Node.js can be found in this resource.