Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

492
Views
How to run a node-js file on the browser? in other words, How to run a node-js file when an HTML form is submitted?

I want to store the data collected from the HTML form into an excel spreadsheet. When I run the JavaScript file on anaconda prompt it works perfectly fine and when the HTML file is executed on the browser, there are no error. But when I try to link them(using a script tag), I get an error "Uncaught ReferenceError: require is not defined".

Here is the JavaScript code:

const info = [];

function display(e){
    //Part1
    e.preventDefault();
    var nm = document.getElementById("nm").value;
    var ag = document.getElementById("ag").value;
    var data = [nm, ag];
    info.push(data);
    var text = document.createElement("h2"); 
    text.innerHTML = info;
    document.body.appendChild(text);
    console.log(info); 

    // -------------------------------------------------
    
    //Part2
    var Excel = require('exceljs');
    var workbook = new Excel.Workbook();
    workbook.xlsx.readFile("AppendRow.xlsx").then(function(){
    worksheet = workbook.getWorksheet("Main")
    worksheet.addRows(data);

    workbook.xlsx.writeFile("AppendRow.xlsx")
    });

    alert('Row has been Appended!')
}

In Part1, the input data is formatted into a list so that it can be easily appended into the excel file.

In Part2, the list is being appended to the excel file.

Here is the HTML part of the code:

<script src="script.js"></script>
<form onsubmit="display(event)"> 
  <input type="text" placeholder="Name" id="nm">
  <input type="text" placeholder="Age" id="ag">
  <input type="submit" value="Submit">
</form>

I can't really figure what could be wrong....According to another source online, I installed browserify and tried to execute it using this module but it didn't work.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!