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?
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?
Share Improve this question edited Feb 20, 2012 at 23:47 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Feb 20, 2012 at 23:20 grauturgrautur 30.5k34 gold badges96 silver badges129 bronze badges1 Answer
Reset to default 8You're not passing a callback to readFile
to 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744317056a4568235.html
评论列表(0条)