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

122
Views
How to Read / Write / Edit Files with Javascript

I want to create a game that saves your progress using files. Is it possible to do something along the lines of this pseudo-code?

/*game_data = The game's content*/
function saveGame () {
    create_file(game_data, "your-game-progress.txt")
}
function loadGame () {
    game_data = load_file("your-game-progress.txt")
}

Is there any way to accomplish this, with or without external libraries?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Are you using a framework like React or NextJS? If so, there are several options for flat-file storage.

If you're using vanilla JS, your only real option for client-side storage is the localStorage() method.

/*game_data = The game's content*/
var game_data = {
   "player_name": "Joe",
   "experience": 4347873,
   "level": 10,
   "HP": 255
};

function saveGame () {
    localStorage.setItem('game_data', game_data);
    //create_file(game_data, "your-game-progress.txt")
}
function loadGame () {
    game_data = localStorage.getItem('game_data');
    //game_data = load_file("your-game-progress.txt")
}

function deleteGame() {
    localStorage.removeItem('game_data');
    /* OR */
    localStorage.clear(); // clears all local storage items
}

The problem, however, is the game data will be lost when the cookie expires or the user clears their cookies or uses a different browser. You might want to consider a server-side solution.

about 4 years ago · Juan Pablo Isaza Report
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!