Home » Nodejs » What are the benefits of using the 'official' temp directory for the OS?

What are the benefits of using the 'official' temp directory for the OS?

Posted by: admin November 29, 2017 Leave a comment

Questions:

I’ve noticed packages like node-temp and node-tmp, which provide APIs for writing temporary files to the appropriate temp directory for the current OS, e.g. /tmp.

What are the benefits of doing this, compared with simply storing temporary files in a subdirectory of your module/application (e.g. ./temp)?

Answers:

It is certainly operating system specific.

On most Linux systems /tmp is a tmpfs file system, which works much faster (because all data stays nearly in RAM) than a conventional disk file system.

Also, the official /tmp/ file system is often a setuid directory. This impacts on who has the permission to delete files inside it.

And some systems are administrated specially and might have periodic cron jobs to clean that /tmp. Also, system administrators know about /tmp/ (and might avoid making backups of it, put it on a fast disk, if not on tmpfs etc…) …. And the Linux Standard Base requires it…

You could use also the TMPDIR environment variable.