You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mktmpdir

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mktmpdir

mktmpdir creates a temporary directory

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
14K
20.09%
Maintainers
1
Weekly downloads
 
Created
Source

mktmpdir

Build Status

mktmpdir creates a temporary directory, ported from Ruby's Dir.mktmpdir.

var mktmpdir = require('mktmpdir');

mktmpdir(function(err, dir, done) {
  if (err) throw err;
  // use the directory...
  fs.writeFile(dir + '/foo', 'hello, World', done);
}, function(err, dir) {
  // after the directory is removed.
});

Installation

$ npm install mktmpdir

Usage

mktmpdir([prefixSuffix], [tmpdir], callback, [onend])

The prefix and suffix of the name of the directory is specified by prefixSuffix. The directory is created under tmpdir or os.tmpdir() with 0700 permission.

Examples

mktmpdir(function(err, dir) {
  // dir is ".../d..."
});

mktmpdir('foo', function(err, dir) {
  // dir is ".../foo..."
});

mktmpdir(['foo', 'bar'], function(err, dir) {
  // dir is ".../foo...bar"
});

mktmpdir(null, '/var/tmp', function(err, dir) {
  // dir is "/var/tmp/d..."
});

// If a callback is invoked, the path of the directory and its contents are removed.
mktmpdir(function(err, dir, done) {
  if (err) throw err;
  fs.open(dir + '/foo', 'w', function(err, fd) {
    done(err);
  });
}, function(err) {
  // the directory has been removed.
});

// If a callback is not invoked, `mktmpdir` doesn't remove the directory.
mktmpdir(function(err, dir) {
  if (err) throw err;
  fs.open(dir + '/foo', 'w', function(err, fd) {
    // remove the directory.
    exec('rm -rf ' + dir);
  });
});

License

MIT

Keywords

tmp

FAQs

Package last updated on 14 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts