read json file nodejs
const fs = require('fs');
const path = require('path');
let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
read json file nodejs
const fs = require('fs');
const path = require('path');
let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
write json file nodejs
const fs = require('fs');
const path = require('path');
let student = {
name: 'Mike',
age: 23,
gender: 'Male',
department: 'English',
car: 'Honda'
};
fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
read json file node js
function readJsonFile(file) {
let bufferData = fs.readFileSync(file)
let stData = bufferData.toString()
let data = JSON.parse(stData)
return data
}
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");
nodejs include json file
config = require("./yourfile.json"); // Note, "config" can be changed to your liking.
how to use json file in nodejs
// Read Synchrously
var fs = require("fs");
console.log("\n *START* \n");
var content = fs.readFileSync("content.txt");
console.log("Output Content : \n"+ content);
console.log("\n *EXIT* \n");
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us