DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for How to create unique temporary directories in Nodejs?
Omar Dulaimi
Omar Dulaimi

Posted on

How to create unique temporary directories in Nodejs?

π—‘π—Όπ—±π—²π—·π˜€ provides an awesome method that lets you create unique temporary directories.

This is really useful when you need to store some data temporarily then delete them later.

π—‘π—Όπ—±π—²π—·π˜€ helps you further, by concatenating 6 unique characters to the π—½π—Ώπ—²π—³π—Άπ˜… you pick. This results in creating unique directories every single time without worrying about collisions.

Library authors will benefit of this tip as well of course.

Just make sure to avoid trailing 𝗫 characters in the π—½π—Ώπ—²π—³π—Άπ˜…, due to some platform inconsistencies.

mkdtemp


Did you learn something new today?

Like and share this post, and follow me for more!

Top comments (2)

Collapse
 
zoppatorsk profile image
Zoppatorsk

Did not know about that function. Have just used stuff like uuid to generate unique temp directory names. This will come in handy, can drop the uuid dependency.

Collapse
 
omardulaimi profile image
Omar Dulaimi

Yeah, I was amazed when I saw it. Glad you enjoyed my post.

Let's Get Wacky


Use any Linode offering to create something unique or silly in the DEV x Linode Hackathon 2022 and win the Wacky Wildcard category

β†’ Join the Hackathon <-