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

235
Vistas
How to Save/Load Javascript Objects

So, here's the thing.

I need a method to save/load data in a webpage from one session to another.

I tried a few of the answers found here, and the one I felt would work the best for me is this one:

const fs = require('fs');
fs.writeFileSync('test.txt', data);
var text = fs.readFileSync('test.txt','utf8')

Since I'm doing it through an html page, I made sure to declare all the JavaScript libraries('require', 'fs' and 'bluebird') in the main page.

<script type="text/javascript" src="./bluebird.js"></script>
<script type="text/javascript" src="./require.js"></script>
<script type="text/javascript" src="./fs.js"></script>

and even tried it as script type="module", but I'm still getting these errors:

Uncaught Error: Module name "bluebird" has not been loaded yet for context: _. Use require([])
Uncaught TypeError: Cannot set properties of undefined (setting 'requirejsVars')
Uncaught ReferenceError: require is not defined

And I really have no idea what I'm doing wrong.

I also tried using Local Storage and it works perfectly for what I want, except that I need the files to be saved in a pre-determined location, so if there's a way to do that through Local Storage, that's even better.

Also, this is a personal project, so I'll just run it locally, without a server or anything.

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