How to get the path to the temporary files directory in Node.js?

Published March 24, 2021

To get the path or location to the temporary files directory, you can use the tmpdir() method from the os module in Node.js.

/* Get path of temporary files directory in Node.js */

// import os module
const os = require("os");

// get temp directory
const tempDir = os.tmpdir(); // /tmp
  • The method returns the path to the temporary files directory as a string.

See the above code live in repl.it.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter