title: How to save excel workbook using Javascript
body: <p>I have created an HTML form that takes in user data and using exceljs and a few other libraries I store this data into an excel spreadsheet. This part of my code works perfectly fine. However, when I refresh the server, the data stored in the excel file previously gets deleted.</p>
  <p>I believe the reason is that I could not save the excel workbook....but when I searched up for some code to achieve this and executed it...the code didn't work.</p>
  <p>Here is the code that collects user data into the excel worksheet:</p>
  <pre><code>//importing necessary libraries
  const express = require(&quot;express&quot;);
  const morgan = require(&quot;morgan&quot;);
  const Prohairesis = require(&quot;prohairesis&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  const Excel = require(&quot;exceljs&quot;);
  
  const app  = express();
  const port = process.env.PORT || 8081;
  
  var info = []
  
  app
      .use(express.static('public'))
      .use(morgan('dev'))
      .use(bodyParser.urlencoded({extended: false}))
      .use(bodyParser.json())
  
      .post('/api/user', (req, res) =&gt; {
  
          res.json(req.body);
  
          //collecting user data into a javascript string 
          const user = req.body;
          const ud = JSON.stringify(user);
          const user_data = JSON.parse(ud);
          console.log(user_data);
          const user_li = [user_data.first, user_data.email, user_data.stdid, user_data.pwd, user_data.cpwd];
          console.log(user_li);
  
          //some simple validation
          for (i in user_li)
          {
              if (user_data.pwd != user_data.cpwd)
              {
                  console.log(&quot;**Password does not match**&quot;);
                  break;
              }
              if (user_data.pwd == user_data.cpwd)
              {
                  info.push(user_li);
                  console.log(info);
                 
                  //append row to excel worksheet
                  const workbook = new Excel.Workbook();
                  const worksheet = workbook.addWorksheet('Main Db');
                  worksheet.addRows(info);
                  workbook.xlsx.writeFile(&quot;Login-Db.xlsx&quot;)
                  console.log('Row has been appended');
                  break;
              }
          }
  
      })
  
      .listen(port, () =&gt; console.log('Server listening on port ${port}'));
  </code></pre>