Jerome
Jerome

Reputation: 1192

Create a text file using JavaScript without using web interface

I'm looking for a method to create + write a text file using JavaScript but I only found method with browser. I don't need my browser to do that, I want to implement a method in my code that write data in a text file nothing to do with the browser.

So someone know how to do this ?

Upvotes: 0

Views: 376

Answers (1)

Andrew Monks
Andrew Monks

Reputation: 666

Use Node.Js:

Node.js Write a line into a .txt file

Something like:

var fs = require('fs')

var logger = fs.createWriteStream('log.txt', {
  flags: 'a' // 'a' means appending (old data will be preserved)
})

logger.write('some data') // append string to your file
logger.write('more data') // again
logger.write('and more') // again

https://nodejs.org/api/fs.html

Upvotes: 2

Related Questions