title: How to store files in local storage
body: <p>I am building an online code editor. Currently, I am storing the source file and input file on my server. Is there any way to store the source files on the client-side? I am using UUID to generate a random filename but want to keep it main.c, main.CPP, just online GDB. But if I cannot have a constant file name or collide when other users are using it.</p>
  <p>the code to generate the file</p>
  <pre><code>const path = require(&quot;path&quot;);
  const { v4: uuid } = require(&quot;uuid&quot;);
  
  const dirCodes = path.join(__dirname, &quot;codes&quot;);
  const inputPath = path.join(__dirname, &quot;inputs&quot;);
  
  if (!fs.existsSync(dirCodes)) {
    fs.mkdirSync(dirCodes, { recursive: true });
  }
  if (!fs.existsSync(inputPath)) {
    fs.mkdirSync(inputPath, { recursive: true });
  }
  
  const generateFile = async (jobId, format, content, input) =&gt; {
    const filename = `${jobId}.${format}`;
    const inputFileName = `${jobId}.txt`;
    const inputFilePath = path.join(inputPath, inputFileName);
    const filepath = path.join(dirCodes, filename);
    await fs.writeFileSync(filepath, content);
    await fs.writeFileSync(inputFilePath, input);
    return [filepath, inputFileName];
  };
  
  module.exports = {
    generateFile,
  };
  </code></pre>
  <p>code for executing the file</p>
  <pre><code>const fs = require(&quot;fs&quot;);
  const path = require(&quot;path&quot;);
  const { v4: uuid } = require(&quot;uuid&quot;);
  
  const dirCodes = path.join(__dirname, &quot;codes&quot;);
  const inputPath = path.join(__dirname, &quot;inputs&quot;);
  
  if (!fs.existsSync(dirCodes)) {
    fs.mkdirSync(dirCodes, { recursive: true });
  }
  if (!fs.existsSync(inputPath)) { random file names will not work for java as we run the class name
    fs.mkdirSync(inputPath, { recursive: true });
  }
  
  const generateFile = async (jobId, format, content, input) =&gt; {
    const filename = `${jobId}.${format}`;
    const inputFileName = `${jobId}.txt`;
    const inputFilePath = path.join(inputPath, inputFileName);
    const filepath = path.join(dirCodes, filename);
    await fs.writeFileSync(filepath, content);
    await fs.writeFileSync(inputFilePath, input);
    return [filepath, inputFileName];
  };
  
  module.exports = {
    generateFile,
  };
  </code></pre>
  <p>I want to keep the file name constant. Also, random file names will not work for java as we run the classname.class file.
  Please let me know if can store the file in client side or local storage</p>