Skip to content

Instantly share code, notes, and snippets.

@michaelerobertsjr
Created February 4, 2017 23:16
Show Gist options
  • Save michaelerobertsjr/d302854f0e06a3d002948adff989b72a to your computer and use it in GitHub Desktop.
Save michaelerobertsjr/d302854f0e06a3d002948adff989b72a to your computer and use it in GitHub Desktop.
var fs = require('fs')
function readfile() {
new Promise(function (resolve, reject) {
fs.readFile('app/topspots.json', 'utf-8', function (err, file) {
if (err) {
console.log('Inside Error: ')
console.log(err);
return reject(err);
}
resolve(file);
});
}).then(function(data){
console.log(data);
}).catch(function(error){
console.log('Inside Catch: ');
console.log(error)
})
}
// function readfile(callback) {
// fs.readFile('app/topspots.json', 'utf-8', function (err, file) {
// if (err) {
// callback(err);
// }
// callback(null, file);
// });
// }
//
// function fileHandler(error, file){
// if (err) {
// console.log(err);
// }
// console.log(file);
// }
readfile();
//readfile(fileHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment