0

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 ?

Jerome
  • 1,162
  • 2
  • 16
  • 32
  • 3
    Do you mean using node.js? – emiliopedrollo Feb 08 '17 at 11:21
  • 1
    There are dozens of tools that execute JavaScript without using a browser. You're question boils down to asking for a recommendation for which tool to use to run the JS. Shopping questions are off-topic for Stackoverflow. – Quentin Feb 08 '17 at 11:22
  • @Quentin I don't really understand your first sentence I mean why you tell me that but I agree that maybe it's off-topic – Jerome Feb 08 '17 at 11:25
  • @emiliopedrollo yes I use Node.js so I'll look into it – Jerome Feb 08 '17 at 11:28
  • 3
    http://stackoverflow.com/questions/2496710/writing-files-in-node-js this question answer perfectly about my problem. I think @emiliopedrollo you should put an answer because I have find it with your hint about node.js – Jerome Feb 08 '17 at 11:29
  • 1
    @Jerome you could accept Andrew Monks answer as he already did one that points to the right way. – emiliopedrollo Feb 08 '17 at 11:43

1 Answers1

2

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

Community
  • 1
  • 1
Andrew Monks
  • 656
  • 4
  • 11
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/15143143) – Sid Feb 08 '17 at 11:46
  • Amended my answer. Thanks – Andrew Monks Feb 08 '17 at 11:50
  • Thank you it's better now ! Have a nice day – Jerome Feb 08 '17 at 12:15
  • Thanks. This helps understand the answer much better. – Sid Feb 08 '17 at 12:34