I want to create a temporary file / directory in node.js. For this, I am trying to execute a simple algorithm:
- Creating a file name based on pid, time and random chars
- Check if file exists
- if yes: go back to step 1 and repeat
- if not: create file and return it
Here's the problem: The node.js documentation for fs.exists explicitly indicates that fs.exists should not be used, and instead just use fs.open and catch a potential error: http://nodejs.org/docs/latest/api/ fs.html # fs_fs_exists_path_callback
In my case, I am not interested in opening a file, if it exists, I am strictly trying to find the name of a file that does not exist yet. Is there a way that I can do this that fs.exists does not use? Alternatively, if I use fs.exists , should I be worried that this method will become obsolete in the future?
user2221343
source share