Dr James Sprinks
Dr James Sprinks

Reputation: 121

Writing to a text file in coffeescript

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.

Upvotes: 2

Views: 3673

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146124

fs = require "fs"
fs.writeFile "classification.json", JSON.stringify(@classification), (error) ->
  console.error("Error writing file", error) if error

Upvotes: 5

Related Questions