Is it possible to write to a file (on a disk) using JavaScript?

后端 未结 9 1108
走了就别回头了
走了就别回头了 2020-11-28 14:51

I am a novice-intermediate programmer taking a stab at AJAX. While reading up on JavaScript I found it curious that most of the examples I\'ve been drawing on use PHP for su

相关标签:
9条回答
  • 2020-11-28 15:08

    You can write cookies with Javascript, on newer browsers you also have an SQLite database to store client side data. You cannot store data in an arbitrary location on the disk though.

    0 讨论(0)
  • 2020-11-28 15:12

    Next version of chrome (v52) made this possible with fetch api + service worker + streams, you can enable streams now with a flag...

    you can go to the StreamSaver.js to see some examples of how to use it.

    You can do something like this:

    const writeStream = fs.createWriteStream('filename.txt')
    const encoder = new TextEncoder
    let data = 'a'.repeat(1024)
    let uint8array = encoder.encode(data + "\n\n")
    
    writeStream.write(uint8array)
    writeStream.close()
    

    Or just go ahead and look at the demos: https://jimmywarting.github.io/StreamSaver.js/example.html

    0 讨论(0)
  • 2020-11-28 15:17

    You can in Windows Scripting Host.

    0 讨论(0)
提交回复
热议问题