2

I am currently writing a string of text to the console for testing reasons, as below:

console.log JSON.stringify @classification

How do I write this to a text file in coffeescript?

Cheers

James

In node.js - and I want to write to a filename of my choosing - not a default log file.

1 Answers1

5
fs = require "fs"
fs.writeFile "classification.json", JSON.stringify(@classification), (error) ->
  console.error("Error writing file", error) if error
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • if "classification.json" does not work, try: path.resolve(__dirname, ".", "classification.json") (you'll need path = require "path") – ZpaceZombor Jan 12 '18 at 14:13