Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda