Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = require("fs")
- readJSON = (path, cb) ->
- fs.readFile path, "utf8", (err, data) ->
- if err
- return cb err
- try
- json = JSON.parse(data)
- catch error
- return cb error
- cb null, json
- readJSONFiles = (files, cb) ->
- results = {}
- remaining = files.length
- files.forEach (file) ->
- readJSON file, (err, json) ->
- if err
- return cb err
- results[file] = json
- cb null, results unless --remaining
- # cb(null,results)
- #files = ["wellformed.json","malformed.json","wellformed_2.json"]
- files = ["wellformed.json","wellformed_2.json"]
- readJSONFiles files, (err, data) ->
- console.log "callback called"
- console.log data
- console.log "end"
Add Comment
Please, Sign In to add comment