Node.js fs read and parse json file

Description

Node.js fs read and parse json file


var fs = require("fs");

console.log("\nStarting node.js server...\n");

// program will not skip until this is finished!
var contents = fs.readFileSync("./files/config.json");

console.log("config.json contents: " + contents + "\n");

// parse the contents
var config = JSON.parse(contents);

console.log("config object: ", config);
console.log("\n");

console.log("username: ", config.username);
console.log("password: ", config.password);
console.log("api_key: ", config.api_key);
console.log("version: ", config.version);
console.log("author: ", config.author);

console.log("\nContinue executing...\n");



PreviousNext

Related