I try to read local file with coffescript and node.js. My code:
fs = require('fs')
foo = () ->
return (fs.readFileSync config, 'utf8')
File is not empty. But when i call foo
i got empty string. How can i read file to string correctly?
Thank you
It's difficult to tell what you're doing wrong as you only show part of your program, but here is a demonstration of a similar program working.
test.txt:
testing
test.coffee:
fs = require 'fs'
config = 'test.txt'
foo = ->
fs.readFileSync config, 'utf8'
console.log foo()
Output:
$ coffee test.coffee
testing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.