javascript - Reading a local file with Coffeescript - Stack Overflow

I'm trying to read in a file with Coffeescript. In the same folder where I enter into the coffee r

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

You'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

相关推荐

  • javascript - Reading a local file with Coffeescript - Stack Overflow

    I'm trying to read in a file with Coffeescript. In the same folder where I enter into the coffee r

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信