1. mktemp
mktemp command for node.js
mktemp
Package: mktemp
Created by: sasaplus1
Last modified: Wed, 03 May 2023 03:33:11 GMT
Version: 1.0.1
License: MIT
Downloads: 1,779,077
Repository: https://github.com/sasaplus1/mktemp

Install

npm install mktemp
yarn add mktemp

mktemp

Build Status
npm version
Try mktemp on RunKit
renovate

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;

  // path match a /^[\da-zA-Z]{5}\.txt$/
  console.log(path);
});

// return value match a /^[\da-zA-Z]{5}\.tmp$/
mktemp.createFileSync('XXXXX.tmp');

mktemp.createDir('XXXXXXX', function(err, path) {
  if (err) throw err;

  // path match a /^[\da-zA-Z]{7}$/
  console.log(path);
});

// return value match a /^XXX-[\da-zA-Z]{3}$/
mktemp.createDirSync('XXX-XXX');

if support Promise, can use Promise style.

 var mktemp = require('mktemp');

mktemp
  .createFile('XXXXX.txt')
  .then(function(path) {
    // path match a /^[\da-zA-Z]{5}\.txt$/
    console.log(path);
  })
  .catch(function(err) {
    console.error(err);
  });

mktemp
  .createDir('XXXXX')
  .then(function(path) {
    // path match a /^[\da-zA-Z]{5}$/
    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');  // match a /^[\da-zA-Z]{7}$/
mktemp.createFileSync('XXX.tmp');  // match a /^[\da-zA-Z]{3}\.tmp$/
mktemp.createFileSync('XXX-XXX');  // match a /^XXX-[\da-zA-Z]{3}$/

Functions

createFile(template[, callback])

  • template
    • String - filename template
  • callback
    • function(err, path) - callback function
      • err : Error|Null - error object
      • path : 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
    • String - path

sync version createFile.

createDir(template[, callback])

  • template
    • String - dirname template
  • callback
    • function(err, path) - callback function
      • err : Error|Null - error object
      • path : 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
    • String - path

sync version createDir.

Contributors

License

The MIT license.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code