Created
May 23, 2017 20:34
-
-
Save cjoshmartin/a66c7693cf1696ba56eee42bea116779 to your computer and use it in GitHub Desktop.
reading in a file synchronous
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
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