Created
June 17, 2018 18:41
-
-
Save kimmobrunfeldt/53a58c1d0f936f78fc5e5be9e23382b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
if (!process.argv[2]) { | |
console.error('Incorrect parameters'); | |
console.error('Usage: ./analytics.js <json-file>'); | |
process.exit(2); | |
} | |
function read(onData) { | |
return new Promise((resolve, reject) => { | |
const rStream = fs.createReadStream(INPUT_PATH, { encoding: 'utf8' }); | |
rStream.on('end', resolve) | |
rStream.on('error', reject) | |
rStream.on('data', onData) | |
}); | |
} | |
function main() { | |
const INPUT_PATH = process.argv[2]; | |
return read((data) => { | |
throw new Error('Imagine this error was thrown by JSON.parse(data)'); | |
}); | |
} | |
main() | |
.catch(err => { | |
console.error('Error happened:', err) | |
throw err; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment