Ask coding questions

← Back to all posts
JavaScript Files Writing?
ARDaSSANDHU (0)

Hello,

How do you save info to a file in javascript on repl.it??

Comments
hotnewtop
tussiez (1427)

Here's some code that makes a text file:

let filename = 'nevergonnagiveyouup.txt';
let fileContent = `We're no strangers to love..`;
let file = new Blob([fileContent],{type: 'text/plain'});

const downloadFile = (bl,name) => {
let aEle = document.createElement('a');
aEle.setAttribute('href',window.URL.createObjectURL(bl));
aEle.setAttribute('download',name);
document.body.appendChild(aEle);
aEle.click(); // Click to download
}

downloadFile(file,filename); // Download!
Coder100 (16760)

you can't.

You need a backend, i would recommend node.js