title: How to Remove last Character in json file with node js
body: <p>I am using Nodejs and i am learning more about the fs module. The data storage file type i have been using is JSON. </p>
  
  <p>I am fairly new to the fs module and want to take the last } of my stock.json out to enter new data and put it back in so it can be called later in my full code</p>
  
  <p>Here is the code i am trying to use</p>
  
  <pre><code>fs.readFile(filestockname, "UTF8", function(err, data) {
              if (err) { throw err };
              global_data = data;
              var stocknames = item
              console.log("File Read")
              fs.writeFileSync('.//settings/Stock/stock.json', global_data+"\r\n" +'"'+stocknames+'"'+"\r\n"+"{"+"\r\n"+'"'+"instock"+'"'+":"+ "1"+"\r\n"+'"'+"stocklimit"+'"'+":"+ "200"+"\r\n"+"}", (err) =&gt; {
              if (err) throw err;
              });
              });
          }
  </code></pre>
  
  <p>Here is the code that is in my stock.json</p>
  
  <pre><code>}
      "Scrap Metal":{
      "instock":1,
      "stocklimit":200
      }
  }
  </code></pre>