mktemp
mktemp command for node.js
Installation
$ npm install mktemp
Usage
var mktemp = require('mktemp');
mktemp.createFile('XXXXX.txt', function(err, path) {
if (err) throw err;
console.log(path);
});
mktemp.createFileSync('XXXXX.tmp');
mktemp.createDir('XXXXXXX', function(err, path) {
if (err) throw err;
console.log(path);
});
mktemp.createDirSync('XXX-XXX');
if support Promise, can use Promise style.
var mktemp = require('mktemp');
mktemp
.createFile('XXXXX.txt')
.then(function(path) {
console.log(path);
})
.catch(function(err) {
console.error(err);
});
mktemp
.createDir('XXXXX')
.then(function(path) {
console.log(path);
})
.catch(function(err) {
console.error(err);
});
mktemp functions are replace to random string from placeholder "X" in template. see example:
mktemp.createFileSync('XXXXXXX');
mktemp.createFileSync('XXX.tmp');
mktemp.createFileSync('XXX-XXX');
Functions
createFile(template[, callback])
template
String
- filename template
callback
function(err, path)
- callback function
err
: Error|Null
- error objectpath
: String
- path
create blank file of unique filename. permission is 0600
.
it throws TypeError if node.js unsupported Promise and callback is not a function.
createFileSync(template)
template
String
- filename template
return
sync version createFile.
createDir(template[, callback])
template
String
- dirname template
callback
function(err, path)
- callback function
err
: Error|Null
- error objectpath
: String
- path
create directory of unique dirname. permission is 0700
.
it throws TypeError if node.js unsupported Promise and callback is not a function.
createDirSync(template)
template
String
- dirname template
return
sync version createDir.
Contributors
License
The MIT license.