DEV Community

Cover image for How to get the path to the temporary files directory in Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode
  • 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 ๐Ÿ˜ƒ.


Top comments (2)

Collapse
 
psanders profile image
Pedro Sanders

Thanks. This was helpful.

Collapse
 
melvin2016 profile image
MELVIN GEORGE

Glad to be of help ๐Ÿ˜ƒ