How do I read a JSON file in node JS

In this post we have learn how do i read a json file in node js. Also we have learn how do i write a json file in node js, node js write json to file, How do I import a JSON file into node js, How do I return a JSON object in node JS.

To include the File System module, use the require() method:

var fs = require('fs');

Example : Read and Write json file in node js


const fs = require("fs")

const jsondata = {
  name : "",
  age : 21

const json = JSON.stringify(jsondata);
fs.writeFile("json1.json", json, (err) => {

fs.readFile("json1.json","utf-8",(err, data) =>{
  const jsonobj = JSON.parse(data);