How to use the tmpName function from tmp

Find comprehensive JavaScript tmp.tmpName code examples handpicked from public code repositorys.

tmp.tmpName is a function in Node.js that generates a unique temporary file or directory name.

134
135
136
137
138
139
140
141
142
143
  res.resume();
  reject(error);
  return;
}

tmp.tmpName(
  function _tempNameGenerated(err, tmpFilename) {
    if (err) {
      reject(err);
      return;
fork icon257
star icon757
watch icon77

41
42
43
44
45
46
47
48
49
50
const tmp = require('tmp');
const im  = require('imagemagick');

fdk.handle((buffer, ctx) => {
  return new Promise((resolve, reject) => {
    tmp.tmpName((err, tmpFile) => {
      if (err) throw err;
      fs.writeFile(tmpFile, buffer, (err) => {
        if (err) throw err;
        im.identify(['-format', '{"width": %w, "height": %h}', tmpFile],
fork icon23
star icon14
watch icon3

How does tmp.tmpName work?

tmp.tmpName() is a function that asynchronously generates a unique filename/path based on a specified prefix, suffix, and directory location using a randomly generated name. It returns a Promise that resolves with the generated filename/path as a string. If no directory location is specified, it uses the default temporary directory location for the system.

5
6
7
8
9
10
11
12
13
14
exports.process = function(path, lang, callback){
        tmp.tmpName({ postfix: '.tif' }, function(err, tif){
                exec(['convert', '-type', 'Grayscale', path, tif].join(' '), function(err, stdout, stderr){
                        fs.unlink(path, function(){})
                        if(stderr) return callback(stderr);
                        tmp.tmpName({ postfix: '.txt' }, function(err, charname){
                                if(err) return callback(err);
                                exec([__dirname + '/tessrec', lang, tif, charname].join(' '), function(err, stdout, stderr){
                                        fs.readFile(charname, function(err, chardata){
                                                fs.unlink(tif, function(){})
fork icon5
star icon18
watch icon5

+ 3 other calls in file

54
55
56
57
58
59
60
61
62
63
write(key: string, content: string): Promise<void> {
    let directory = dirname(key);

    return ensureDir(directory).then(() => {
        return new Promise((resolve, reject) => {
            tmpName({
                dir: directory,
                postfix: extname(key)
            }, (err: any, tmpFile: string) => {
                writeFile(tmpFile, content, (err) => {
fork icon23
star icon14
watch icon2

Ai Example

1
2
3
4
5
6
const tmp = require("tmp");

tmp.tmpName((err, path) => {
  if (err) throw err;
  console.log("Temporary file path:", path);
});

This code generates a unique temporary file path using the tmpName method and logs it to the console. If an error occurs during the operation, it will be thrown.

33
34
35
36
37
38
39
40
41
42
  return getResource(name, root);
};

const tmpName = () => {
  return new Promise((resolve, reject) => {
    tmp.tmpName((err, name) => {
      if (err) {
        reject(err);
      } else {
        resolve(name);
fork icon1
star icon5
watch icon2

18
19
20
21
22
23
24
25
26
27
var src = file.src;
var dest = file.dest;

var extension = path.extname(file.src).toLowerCase();

tmp.tmpName({
  postfix: extension
}, function(error, tmpDest) {

  if (error || !tmpDest) {
fork icon1
star icon2
watch icon3

102
103
104
105
106
107
108
109
110
111
    return
}

util.log(util.format('CAPT %s', parsed.url))

tmp.tmpName({postfix: '.png'}, function(err, filename) {
    if (err) {
        util.log('ERR  unable to create a file')
        result.status(500).send(EMSG.file)
        return
fork icon0
star icon0
watch icon0

23
24
25
26
27
28
29
30
31
32
    return system('rm -f ' + path);
}

function tmpname() {
    return new Promise(function(resolve, reject) {
        tmp.tmpName(function(err, path) {
            if(err) {
                reject(err);
                return;
            }
fork icon0
star icon0
watch icon2