title: Next Js Server Side Api Read and Write JSON
body: <p>I'm trying to write a basic local api for myself using Next.js, it is a timeline generator, and I am stuck at actually reading the file from the api folder.</p>
  <p>What do I want in my local aplication:</p>
  <p>1.A simple page where I can input an event, with a date and description</p>
  <p>2.Open a list.json file somewhere and push that new event to that json file, writing on it.</p>
  <p>What I am currently doing and where I am stuck:</p>
  <p>I am aware we cant write on files on the client side, so I started looking at the api routes in next js to access the JSON file, but I cannot even manage to read it!</p>
  <p>I have an api folder inside pages folder, and in this api folder I have two files: one is the list.json file, where I previously manually write some events with respective dates; and the other is getlist.js, with this code:</p>
  <pre><code>var fs = require('fs');
  
  export default function getList(req, res) {
      const rawList = fs.readFile('list.json');
      var list = JSON.parse(rawList);
      res.json(list);
  }
    
  </code></pre>
  <p>Now on the pages folder I have a index.js file where I try to access this getlist.js api using getStaticProps(), like this:</p>
  <pre><code>import getlist from './api/getlist'
  
  export async function getStaticProps(){
  
      var list = getlist();
  
      return {
          props: {
              list
          }
      }
  }
  </code></pre>
  <p>I have tried using other stuff, like the fecth function, to get to getlist.js, but nothing I do seems to work.</p>
  <p>Can anyone help me?</p>
  <p>And since I'm already in here, how would I manage to get the input from the form I already have in my client side page and write it to that list.json file in my api folder?</p>