Ask coding questions

← Back to all posts
Txt file js
r3b0rn (27)

How do you edit text files using js not node js but js

Answered by EpicGamer007 (1751) [earned 5 cycles]
View Answer
Comments
hotnewtop
EpicGamer007 (1751)

Simple answer is, you cannot, browser js cannot access the file system.

r3b0rn (27)

@EpicGamer007 thats interesting! thanks anyway

SixBeeps (5334)

To further elaborate on what @EpicGamer007 said:

If browser JS had access to the local file system, that would mean anyone could make a website to simply delete all of your files in one go, all without user input. Not good.

Instead, if you were to use Node.js, that works in the application scope rather than in the internet scope. Thus, there'd be no danger in allowing access to the local file system.

What exactly are you looking to achieve by editing a file on the local system?

r3b0rn (27)

@SixBeeps i was gonna use it to save stuff from my game, idk how to do anything like thtat

r3b0rn (27)

@SixBeeps In other words, scores of people to make a leaderboard!

SixBeeps (5334)

@r3b0rn Read into localStorage, which allows access to a very limited portion of the file system. It doesn't let you use a full .txt file, but instead it acts as a dictionary specific to your game that you can change.

EpicGamer007 (1751)

@r3b0rn if you want to make a leaderboard, you need a database on the server (unless you want to leaderboard to be local only)

r3b0rn (27)

@SixBeeps is there a way to get someones repl username in js?