Reputation: 7330
from nodejs documentation on fs.mkdtemp
const tmpDir = '/tmp';
const subdir = '/com.domain.app';
!fs.existsSync(tmp + subdir) ? fs.mkdirSync(tmp + subdir) : null;
// This method is *CORRECT*:
const path = require('path');
fs.mkdtemp(tmpDir + path.sep + subdir + path.sep, function(err, folder){
if (err) throw err;
console.log(folder);
});
My question is related to path.sep
and temp directories and I want the code to be platform agnostic, and to be able to run on multiple platforms.
path.sep
across all nodejs platforms./tmp
available on windows?Thanks
Upvotes: 2
Views: 2085
Reputation: 7330
Use os.tmpDir
and path.join
functions for cross platform code.
var tmp = require('os').tmpDir();
var dest = path.join(tmp, "com.domain.app");
!fs.existsSync(dest) ? fs.mkdirSync(dest) : null;
Reference. Writing cross platform node
Upvotes: 1