Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!