How to use the tmpdir function from os

Find comprehensive JavaScript os.tmpdir code examples handpicked from public code repositorys.

os.tmpdir is a method in Node.js that returns the default directory for temporary files on the current operating system.

532
533
534
535
536
537
538
539
540
541
  files = filesFromFields.call(this, this.body)
} else {
  files = await this.files(options)
}
const requestFiles = []
const tmpdir = (options && options.tmpdir) || os.tmpdir()
this.tmpUploads = []
for await (const file of files) {
  const filepath = path.join(tmpdir, toID() + path.extname(file.filename))
  const target = createWriteStream(filepath)
fork icon81
star icon312
watch icon21

37
38
39
40
41
42
43
44
45
46
47
var request = require('request');
var unzip = require('unzip-stream');
var async = require('async');
var readline = require('readline');
var os = require("os");
const tempDir = os.tmpdir();
const { basename } = require('path');


// All data from http://download.geonames.org/export/dump/
var GEONAMES_URL = 'https://download.geonames.org/export/dump/';
fork icon51
star icon157
watch icon10

+ 7 other calls in file

How does os.tmpdir work?

os.tmpdir() is a function in Node.js that returns the operating system's default directory for temporary files. The location of this directory varies depending on the operating system and can be configured using environment variables. On Unix-like systems, it defaults to /tmp. On Windows, it defaults to C:\Users\Username\AppData\Local\Temp.

30
31
32
33
34
35
36
37
38
39
"http_keep_alives": "default",
"http_timeout": 120,
"http_static_index": "index.html",
"http_static_ttl": 0,
"http_max_upload_size": 32 * 1024 * 1024,
"http_temp_dir": os.tmpdir(),
"http_gzip_opts": {
	"level": zlib.constants.Z_DEFAULT_COMPRESSION, 
	"memLevel": 8 
},
fork icon2
star icon7
watch icon0

98
99
100
101
102
103
104
105
106
107
108
    getSketchBuild();
    elf_path_input.value = elf_file_auto_path;
}


function getSketchBuild() {
    var tempFolder = os.tmpdir();
    var mostRecentBuild = "";
    var mostRecentTimestamp = 0;
    var files = fs.readdirSync(tempFolder);
    files.forEach(file => {
fork icon0
star icon2
watch icon1

Ai Example

1
2
3
const os = require("os");

console.log(os.tmpdir()); // prints the path of the temporary directory on your operating system

This will log the path of the temporary directory used by your operating system to the console. The output may vary depending on your operating system.

6
7
8
9
10
11
12
13
14
15
var path = require('path');
var fs = require('fs');
const bodyParser = require("body-parser");
const sqlite3 = require('sqlite3').verbose();
const {exec} = require("child_process");
const form = formidable({uploadDir: os.tmpdir()});
var AesCmac = require('node-aes-cmac').aesCmac;
const decSHE = require('she_decrypt');
const encSHE = require('she_encrypt');
var app = require('../app');
fork icon0
star icon2
watch icon1

78
79
80
81
82
83
84
85
86
87
    autoWatch: false,
    singleRun: true,
    reporters: ['dots'],
};

var path = commander.path || os.tmpdir();
path += '/karma/portal';

karmaOptions.preprocessors = {};
_.each(getFirstPartyFiles(), function(value) {
fork icon1
star icon0
watch icon0

247
248
249
250
251
252
253
254
255
256
    .option('--coverage', 'Enable code coverage')
    .option('--file <path>', 'File to execute')
    .option('--suite <suite>', 'Test suite to execute')
    .parse(process.argv);

var workspace = commander.path || process.env.WORKSPACE || os.tmpdir();
var args = [];
if (commander.ci) {
    setUpCiConfiguration(workspace);
    args.push(
fork icon1
star icon0
watch icon0

+ 3 other calls in file

20
21
22
23
24
25
26
27
28
29
30
const multer = require('multer')
// const upload = multer({ dest: 'uploads/' })
const os = require('os')
const path = require('path')
// const tmpFolder = path.join(os.tmpdir(), 'uploads')
const upload = multer({ dest: os.tmpdir() })


// import models here
const Video = require('../models/Video.model')
const User = require('../models/User.model')
fork icon1
star icon0
watch icon1

19
20
21
22
23
24
25
26
27
28
29
if (fs.existsSync('/var/dcp/run'))
  DEFAULT_PID_LOC = '/var/dcp/run/';
else if (fs.existsSync('/var/run'))
  DEFAULT_PID_LOC = '/var/run/';
else
  DEFAULT_PID_LOC = os.tmpdir();


const TOTAL_CPU_VCORES = os.cpus().length;
const DEFAULT_CORES = TOTAL_CPU_VCORES - 1;
var worker, dcpConfig;
fork icon0
star icon4
watch icon3

86
87
88
89
90
91
92
93
94
95
this._pathsCache = {
    "home":        homeFolder,
    "appData":     path.dirname(userDataFolder),
    "userData":    userDataFolder,
    "sessionData": userDataFolder,
    "temp":        os.tmpdir(),
    "exe":         process.execPath,
    // "module":      process.execPath,
    "desktop":     path.join(homeFolder, "Desktop"),
    "documents":   path.join(homeFolder, "Documents"),
fork icon0
star icon0
watch icon1

456
457
458
459
460
461
462
463
464
// or the app doesn't installed at all, so no error catching needed.
return Promise.resolve().then(function () {

    var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
    var execOptions = {
        cwd: os.tmpdir(),
        timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
        killSignal: EXEC_KILL_SIGNAL
    };
fork icon0
star icon0
watch icon1

532
533
534
535
536
537
538
539
540
541
// This code will process each file uploaded.
bb.on('file', (fieldname, file, info) => {
  // file.on('error', (e) => {
  //   console.error('File error', e);
  // });
  // Note: os.tmpdir() points to an in-memory file system on GCF
  // Thus, any files in it must fit in the instance's memory.
  jetpack.dir(self.tmpdir)

  const filename = info.filename;
fork icon0
star icon0
watch icon2

22
23
24
25
26
27
28
29
30
    GenerateFromBlueprint: class extends Task {},
    InstallBlueprint: class extends Task {},
    NpmInstall: class extends Task {},
  };

  let tmpDir = os.tmpdir();
  workingDir = `${tmpDir}/ember-cli-test-project`;
  fs.mkdirSync(workingDir);
});
fork icon0
star icon0
watch icon159

22
23
24
25
26
27
28
29
30
31
32
33
const eventEmitter = new events.EventEmitter()


const defaultPort = 1025
const defaultHost = '0.0.0.0'
const defaultMailDir = path.join(
  os.tmpdir(),
  `maildev-${process.pid.toString()}`
)


/**
fork icon0
star icon0
watch icon1

145
146
147
148
149
150
151
152
153
154
        script = script.concat(' -overridermlabels ' + '"' + overridermlabels + '"');
    }
}


let tempDir = os.tmpdir();
let filePath = path.join(tempDir, uuidv4() + '.ps1');
await fs.writeFileSync(
    filePath,
    script,
fork icon0
star icon0
watch icon3

75
76
77
78
79
80
81
82
83
84
    throw new Error('media is not a video');

const videoType = media.mimetype.split('/')[1];

const tempFile = path.join(
    tmpdir(),
    `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`
);

const stream = new (require('stream').Readable)();
fork icon0
star icon0
watch icon1

231
232
233
234
235
236
237
238
239
240
241
};


// Returns a promise.
// TODO: we should remove this, there's a more robust method under android_sdk.js
module.exports.list_targets = function () {
    return superspawn.spawn('android', ['list', 'targets'], {cwd: os.tmpdir()}).then(function (output) {
        var target_out = output.split('\n');
        var targets = [];
        for (var i = target_out.length; i >= 0; i--) {
            if (target_out[i].match(/id:/)) {
fork icon0
star icon0
watch icon2

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
    (options.server.options).cert || fakeCert;
}

if (typeof options.ipc === "boolean") {
  const isWindows = process.platform === "win32";
  const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os.tmpdir();
  const pipeName = "webpack-dev-server.sock";

  options.ipc = path.join(pipePrefix, pipeName);
}
fork icon0
star icon0
watch icon0

216
217
218
219
220
221
222
223
224
225

const report = response.data
const containerName = (report.report_id).toLowerCase()
const blobName = report.storage_file_name
const fileName = blobName+report.original_file_name
console.log("Root " + os.tmpdir())
const filePath =  path.join(os.tmpdir(),`${fileName}`)
const readStream = await azureStorage.downloadBlob(containerName,blobName,filePath)
// setTimeout(()=>{
//       deleteFilesFromLocal(filePath)
fork icon0
star icon0
watch icon1

73
74
75
76
77
78
79
80
81
82
  }
},
subOptionWarning: subOptionWarning,

baseTempDir: function baseTempDir (opts) {
  return path.join(opts.tmpdir || os.tmpdir(), 'electron-packager')
},
generateFinalBasename: generateFinalBasename,
generateFinalPath: generateFinalPath,
sanitizeAppName,
fork icon0
star icon0
watch icon1