“cara membaca file json di node js” Kode Jawaban

Baca JSON File Node JS

function readJsonFile(file) {
    let bufferData = fs.readFileSync(file)
    let stData = bufferData.toString()
    let data = JSON.parse(stData)
    return data
}
Lucky Lion

Tulis NodeJs File JSON

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));
Victor Grk

node.js membaca file json

//Condensed
JSON.parse(fs.readFileSync("path").toString())
Thankful Toucan

Cara Mendapatkan Data JSON dari file JSON di Node JS

const fs = require("fs"); 
var posts = [];

fs.readFile('./data/posts.json', 'utf8', (err, data) => {
                if (err) throw err;
                posts = JSON.parse(data);
            });
Magnificent Millipede

cara membaca file json di node js

const path = require('path')
const fs = require('fs')

blogs = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/blogs.json')).toString())
Strange Snake

Jawaban yang mirip dengan “cara membaca file json di node js”

Pertanyaan yang mirip dengan “cara membaca file json di node js”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya