I’m trying to read in a file with Coffeescript. In the same folder where I enter into the coffee repo, I have a file named hello.txt.
coffee> fs = require 'fs'
coffee> x = fs.readFile "hello.txt"
undefined
coffee> x
undefined
What am I doing wrong?
You’re not passing a callback to
readFileto actually read the file. See docs for further information. Generally, nodejs methods are asynchronous because of the asynchronous nature of the platform. For some of them there is a sync version. Indeed, you can read a file with the readFileSync method.