Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

503
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda