4 ms·
You should be using coffeescript though, makes the javascript in the example look like: fs = require('fs') for i in [1..3] fs.readFile 'test.coffee',
by joevandyk 16y ago
You should be using coffeescript though, makes the javascript in the example look like:
fs = require('fs')
for i in [1..3]
fs.readFile 'test.coffee', (err, data) ->
console.log("#{i}. Finished reading file")
console.log("#{i}. doing something important...")
And if you want to get rid of that "gotcha" (which is a javascript one, not a node.js one):
fs = require('fs')
for i in [1..3]
do (i) ->
fs.readFile 'test.coffee', (err, data) ->
console.log("#{i}. Finished reading file")
console.log("#{i}. doing something important...")
This will output the number you'd intuitively inside the file read callback function.
- nolite 16y agodo you need to preprocess the coffescript somehow before node runs it, or will node run it directly?
- marcomonteiro 16y agoYou have to compile it. http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/
- nonames 16y agoNot necessarily. The distributed `coffee` script will automatically compile before running the script. Plus it shows you coffeescript-friendly tracebacks on error.
- marcomonteiro 16y agoWhether I manually compile it or it's automatically compiled it still has to be compiled which was the question I was responding to. Which is to say Node.js will not run CoffeeScript directly.