Skip to content

Instantly share code, notes, and snippets.

@cjoshmartin
Created May 23, 2017 20:34
Show Gist options
  • Save cjoshmartin/a66c7693cf1696ba56eee42bea116779 to your computer and use it in GitHub Desktop.
Save cjoshmartin/a66c7693cf1696ba56eee42bea116779 to your computer and use it in GitHub Desktop.
reading in a file synchronous
var fs = require('fs');
var file ="./nasty.json"
var nastystring;
exports.command = function () {
try {
var data = fs.readFileSync(require('path').resolve(__dirname + "/nasty.json"), 'utf8');
nastystring =JSON.parse(data);
} catch(e) {
console.log('Error:', e.stack);
}
return nastystring[Math.floor(Math.random()* nastystring.length)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment