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

180
Visualizações
Writing an array to a file in javascript

I have an array of 32 strings called "arr" and I'm trying to save it to a file (like a txt file). I'm doing this in javascript because I'm getting this array from an html page.

I've tried this solution : node.js - how to write an array to file

So this code :

var fs = require('fs');

var file = fs.createWriteStream('array.txt');
file.on('error', function(err) { /* error handling */ });
arr.forEach(function(v) { file.write(v.join(', ') + '\n'); });
file.end();

results for me this error :

Error: Module name "fs" has not been loaded yet for context: _. Use require([])

I saw a solution there : https://requirejs.org/docs/errors.html#scripterror and tried this one :

require(['foo'], function (foo) {
    //foo is now loaded.
});

but it still results 3 errors :

  • "Failed to load resource: the server responded with a status of 404 (Not Found)"
  • "Refused to execute http://[...]/scripts/fs.js as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type. defaultOnError — require.js:5:1663"
  • "Error: Script error for "fs""

I'm a beginner in Javascript and I don't really understand how to use require.js. I tried to find a solution but I everything resulted to those errors.

Could you help me to write arrays in a text file ? Thank you for your help !

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