title: How to check if directory exists before writing to it (nodejs)?
body: <p>I was going to use <code>fs.access</code> to see if a directory exists, then if it exists then write a file into that directory, if it's not then first create the directory and then write a file into it. </p>
  
  <p>But in the docs it says this is not recommended `Using fs.access() to check for the accessibility of a file before calling fs.open(), fs.readFile() or fs.writeFile() is not recommended. Doing so introduces a race condition, since other processes may change the file's state between the two calls. </p>
  
  <p>Instead, user code should open/read/write the file directly and handle the error raised if the file is not accessible.` </p>
  
  <p>Is there a recommended way to check first then write ?</p>