admin管理员组文章数量:1405324
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.
本文标签: javascriptReading a local file with CoffeescriptStack Overflow
版权声明:本文标题:javascript - Reading a local file with Coffeescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744317056a2600316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论