How to use the mkdtempSync function from fs-extra
Find comprehensive JavaScript fs-extra.mkdtempSync code examples handpicked from public code repositorys.
fs-extra.mkdtempSync is a synchronous function in the fs-extra library that creates a temporary directory with a unique name.
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
} function make_build_environment(nodes, working_directory, options) { // Create target directory let dest = working_directory ?? fs.mkdtempSync(path.join(os.tmpdir(), app_name)); fs.ensureDirSync(dest); // Create and initialize the manifest builder let mcu_nodes_root = path.resolve(__dirname, "./mcu_modules");
+ 19 other calls in file
40 41 42 43 44 45 46 47 48 49 50
console.log("Either --build or --output <filename> must be specified."); process.exit(1); } const componentSrcDir = path.resolve(process.cwd()); const dockerContextDir = fse.mkdtempSync( path.resolve(__dirname, "..", "docker-context-") ); const componentDestDir = path.resolve(dockerContextDir, "component");
How does fs-extra.mkdtempSync work?
fs-extra.mkdtempSync
is a synchronous function that creates a unique temporary directory with a specified prefix. It returns the path to the newly created directory.
When called, fs-extra.mkdtempSync
generates a unique name by appending random characters to the specified prefix. The function creates the directory with fs.mkdirSync
, including any necessary parent directories.
If the specified prefix is not a string, or if the underlying fs.mkdirSync
call fails for any reason, fs-extra.mkdtempSync
throws an error.
Note that fs-extra.mkdtempSync
is a synchronous function, so it blocks the main thread until the directory is created. If you need to create a temporary directory without blocking the main thread, use the asynchronous fs-extra.mkdtemp
function instead.
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
let tempProjDir; if (projectsOnly) { tempProjDir = outputFolder; } else { // make temporary folder for project tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), wlProjectName)); tempProjDir = tmpDir; } // make link in temporary folder for model file; wonderland engine
+ 14 other calls in file
64 65 66 67 68 69 70 71 72 73
const parentDir = path.join( common.baseTempDir(this.opts), `${this.opts.platform}-${this.opts.arch}` ) fs.mkdirpSync(parentDir) this.cachedStagingPath = fs.mkdtempSync(path.join(parentDir, `${common.generateFinalBasename(this.opts)}-`)) } return this.cachedStagingPath } }
+ 3 other calls in file
Ai Example
1 2 3 4 5
const fs = require("fs-extra"); const dir = fs.mkdtempSync("/tmp/myapp-"); console.log(`Created temporary directory ${dir}`);
In this example, we call fs-extra.mkdtempSync with the prefix '/tmp/myapp-'. The function will append a unique string of characters to this prefix to create a unique directory name. fs-extra.mkdtempSync returns the path to the new temporary directory, which we store in the dir variable. We then log a success message to the console, including the path to the new directory. If an error occurs while creating the directory, fs-extra.mkdtempSync will throw an error object. You can catch this error using a try/catch block if necessary.
fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)