title: Nodejs - Redirecting console.logs to a file in nodejs
body: <p>I have a finalized functioning app, I need to add a log file for errors and accesses
  There are already many console.logs in the whole app in many different folders and files</p>
  
  <p>I read an old answer that suggested using this method below (which seems to be good theoretically), but it doesn't work</p>
  
  <p>How should I do ?</p>
  
  <pre class="lang-js prettyprint-override"><code>const access = fs.createWriteStream(path.join(process.cwd(), "logs", "access.log"), { flag: "a" });
  const error = fs.createWriteStream(path.join(process.cwd(), "logs", "errors.log"), { flag: "a" });
  
  console.log(path.join(process.cwd(), "logs", "errors.log"));
  
  // redirect stdout / stderr
  process.stdout.pipe(access);
  process.stderr.pipe(error);
  </code></pre>