Ask coding questions

← Back to all posts
Saving a string to a txt document
JoyalMathew

Using javascript in repl.it, how would I write a string in a .txt document. I have tried looking online but those solutions don't seem to work on repl.it

I have tired things like

and,

Voters
26youj
JoyalMathew
Comments
hotnewtop
wjustin

@JoyalMatthew in python it is possible

timmy_i_chen

Indeed, you cannot create a txt file using front end JS, and for good reason too! Imagine if websites could write files to your system... heh.

If you want to write to files, you can use Node.js, like mentioned before. Alternatively, you can use Localstorage, which will save it in the browser itself, but you're limited by size (and obviously can only be accessed when using the same computer + browser).

26youj

@timmy_i_chen is there a way for you to edit the txt file?

Vandesm14

But If you want to switch to Nodejs, you can store files on the server using https://www.w3schools.com/nodejs/nodejs_filesystem.asp

JoyalMathew

@Vandesm14 I need to be able to save it as a txt file on repl.it or add it to an existing txt file. Is Nodejs the only way to do this?

timmy_i_chen

@Vandesm14 Edited your comment. You should know better than to link to jsfiddle :|

theangryepicbanana

Maybe try DOMObject instead?

JoyalMathew

@theangryepicbanana no, it gives a
ReferenceError: DOMObject is not defined

theangryepicbanana

@JoyalMathew You might want to look at AJAX then. It's used for lots of stuff like this