Skip to content

Instantly share code, notes, and snippets.

@PetterKraabol
Last active August 29, 2015 14:27
Show Gist options
  • Save PetterKraabol/fe58c23c96c99ffaf645 to your computer and use it in GitHub Desktop.
Save PetterKraabol/fe58c23c96c99ffaf645 to your computer and use it in GitHub Desktop.
Asynchronous JSON reader
var fs = require('fs');
// Read data from file
exports.read = function(file, callback){
fs.readFile(file, function(err, dataString){
if(err) callback(err);
var data = JSON.parse(dataString, function(key, value){
return value;
});
return callback(null, data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment