Skip to content

Instantly share code, notes, and snippets.

@maganap
maganap / temp-working-path.js
Created July 14, 2021 15:47
Create and remove temporary working directory - Node JavaScript
// node 14 tested
const fs = require('fs');
const os = require('os');
const path = require('path');
// this creates a random name directory within the OS temporary directory
const getWorkingPath = () => fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
// make sure to remove the whole path when finished
const removeWorkingPath = (path) => fs.rmSync(path, { recursive: true });