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

233
Visualizações
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 à 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