1.0.2 • Published 10 years ago
temporary-directory v1.0.2
temporary-directory
create a random temporary directory and easily clean it up when you are done
installation
npm install temporary-directoryexample
var tmp = require('temporary-directory')
tmp(function created (err, dir, cleanup) {
if (err) console.error('Error creating tmpdir!', err)
// do cool stuff with dir here...
// later, when you wanna destroy the tmpdir:
cleanup(function cleanedUp (err) {
if (err) console.error('Error removing tmpdir!', err)
})
})API
var tmpdir = require('temporary-directory')
returns a constructor function that can be used to create new temporary directories
tmpdir(name, callback)
name is optional, if you pass it then your tmpdir name will start with name-<random-id>, otherwise it defaults to tmp-<random-id>
callback will be called with err, dir, cleanup
erris if there was an error creating your tmpdirdiris a string of the absolute path to your tmpdir (inside yourrequire('os').tmpdir())cleanupis a function you can call (if you want) that will destroy the tmpdir and everything in it. it takes a singlecallbackargument that takes a singleerrorargument, but the callback is optional.
