How to use the tmpNameSync function from tmp

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

tmp.tmpNameSync is a synchronous function that generates a unique temporary filename.

197
198
199
200
201
202
203
204
205
206
A synchronous version of the above.

```javascript
const tmp = require('tmp');

const name = tmp.tmpNameSync();
console.log('Created temporary filename: ', name);
```

## Advanced usage
fork icon97
star icon711
watch icon7

59
60
61
62
63
64
65
66
67
68
//   'src',
//   '_main.scss',
// );

const addonsThemeLoaderVariablesPath = tmp.tmpNameSync({ postfix: '.scss' });
const addonsThemeLoaderMainPath = tmp.tmpNameSync({ postfix: '.scss' });
fs.writeFileSync(
  addonsThemeLoaderVariablesPath,
  new Buffer.from(getAddonsLoaderCode('variables', variables)),
);
fork icon266
star icon251
watch icon0

+ 3 other calls in file

How does tmp.tmpNameSync work?

tmp.tmpNameSync is a function in the tmp module of Node.js that generates a unique temporary file or directory name synchronously based on a provided prefix, postfix, and directory path.

126
127
128
129
130
131
132
133
134
135
A synchrounous version of the above.

```javascript
var tmp = require('tmp');

var name = tmp.tmpNameSync();
console.log("Created temporary filename: ", name);
```

## Advanced usage
fork icon97
star icon0
watch icon2

+ 3 other calls in file

97
98
99
100
101
102
103
104
105
106
Processor.prototype._tmpName = function (extension) {
  extension = extension || ''

  if (extension.length) extension = '.' + extension

  return tmp.tmpNameSync({ postfix: extension })
}

Processor.prototype._tmpDir = function () {
  return tmp.dirSync().name
fork icon53
star icon262
watch icon18

Ai Example

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

const tmpFileName = tmp.tmpNameSync();

console.log(tmpFileName);

This code will generate a unique temporary filename using the default prefix and postfix, and return it as a string.

145
146
147
148
149
150
151
152
153
154
status.start();
const archive = await this.octokit.repos.getArchiveLink({owner:creds.username, repo:reponame, archive_format:'zipball', ref:branch})
status.stop();
// console.log(archivelink)

let tmpname = tmp.tmpNameSync();
fs.writeFileSync(tmpname, archive.data);

module.exports.tmpdir=tmp.dirSync();
// console.log(tree)
fork icon20
star icon31
watch icon4

21
22
23
24
25
26
27
28
29
30
function apiDefaults() {
  return {
    parallelism: 5,
    bufferSize: 500,
    requestTimeout: 120000,
    log: tmp.tmpNameSync(),
    resume: false,
    mode: 'full'
  };
}
fork icon16
star icon60
watch icon63

496
497
498
499
500
501
502
503
504
505

if ( config.get('user_agent').length > 0 ) tmpWindow.webContents.setUserAgent( config.get('user_agent') );

tmpWindow.webContents.session.once('will-download', (event, downloadItem) => {
	imageCache[url] = file = {
		 path: tmp.tmpNameSync() + '.' + mime.extension(downloadItem.getMimeType())
		,complete: false
	};

	downloadItem.setSavePath(file.path);
fork icon3
star icon4
watch icon0

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17


module.exports = function (spec) {


	let that = null;
	let clips = [];
	let outputFileName = tmp.tmpNameSync({
		prefix: 'video-output-',
    postfix: '.mp4'
	});

fork icon2
star icon4
watch icon0

+ 3 other calls in file

86
87
88
89
90
91
92
93
94
95
const createMediaFile = async ({ path, buffer }, metadata, cb) => {
    const fileModel = require("../models/media_file").model;
    return new Promise(async (resolve, reject) => {
        let filePath = path;
        if (buffer) {
            filePath = tmp.tmpNameSync();
            fs.writeFileSync(filePath, buffer);
        }
        const fsName =
            shortid.generate() + "_" + Date.now() + "." + metadata.extension;
fork icon0
star icon2
watch icon3

195
196
197
198
199
200
201
202
203
204
    "MAINTAINER " + target.dockerfile.maintainer
];
if (options.nocache)
    dockerfileLines.push("RUN echo " + (new Date()).getTime());
dockerfileLines = dockerfileLines.concat(target.dockerfile.commands.split("\n"));
var tempDockerfile = Tmp.tmpNameSync({
    template: targetDir + "/Dockerfile-tmp-XXXXXX"
});
tempFiles.push(tempDockerfile);
FS.writeFileSync(tempDockerfile, dockerfileLines.join("\n"));
fork icon0
star icon2
watch icon0

+ 5 other calls in file

15
16
17
18
19
20
21
22
23
24
25
	
}


function uploadTextFile(text, dst, sftp){
	
	var tmpFile = tmp.tmpNameSync();
	fs.writeFileSync(tmpFile, text, {encoding: 'utf8'});
	
	return new Promise((success, fail) => {
		sftp.fastPut(tmpFile, dst, err => {
fork icon0
star icon0
watch icon2

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
        stderr += data.toString();
    }
};

tmp.setGracefulCleanup();
const filename = tmp.tmpNameSync({postfix: '.py'});
fs.writeFileSync(filename, util ? utilityFunctions + script : script);
try {
    await exec.exec('python', [filename], options);
} catch (error) {
fork icon0
star icon0
watch icon0

125
126
127
128
129
130
131
132
133
134
    var bin = editorOpts.shift();
    this.editor = { args: editorOpts, bin: bin };
};
ExternalEditor.prototype.createTemporaryFile = function () {
    try {
        this.tempFile = tmp_1.tmpNameSync(this.fileOptions);
        var opt = { encoding: "utf8" };
        if (this.fileOptions.hasOwnProperty("mode")) {
            opt.mode = this.fileOptions.mode;
        }
fork icon0
star icon0
watch icon0