I wanted to write a program to retrieve information from keys.json in node.js
import fs from "fs";
var json;
fs.readFile("keys.json", (err, content) => {
if (err) return console.log(err);
json = JSON.parse(content);
console.log(json); // Returns values from JSON file
})
console.log(json); // Returns undefined
I have looked through possible issues such as hoisting and scopes, but I can't seem to find anything relevant. Any ideas? Thanks