Answers for "nodejs import json"

0

how to use json file in nodejs

D:\NodeJs>node readsync.js
 *START*
Output Content:
 /* content here */
*EXIT*
// Define JSON File
 var fs = require("fs");
 console.log("\n *STARTING* \n");
// Get content from file
 var contents = fs.readFileSync("jsoncontent.json");
// Define to JSON type
 var jsonContent = JSON.parse(contents);
// Get Value from JSON
 console.log("User Name:", jsonContent.username);
 console.log("Email:", jsonContent.email);
 console.log("Password:", jsonContent.password);
log("\n *EXIT* \n");
Posted by: Guest on December-05-2020
0

nodejs include json file

config = require("./yourfile.json"); // Note, "config" can be changed to your liking.
Posted by: Guest on January-15-2021
0

node js reuire json shows onject

var readJson = (path, cb) => {
  fs.readFile(require.resolve(path), (err, data) => {
    if (err)
      cb(err)
    else
      cb(null, JSON.parse(data))
  })
}
Posted by: Guest on December-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language