read json file node js

  1. First, import the 'fs' module using the require() function to gain access to the file system module.
  2. Use the fs.readFile() method to read the JSON file, providing the file path and a callback function to handle the file data.
  3. Inside the callback function, parse the data using JSON.parse() to convert the JSON string into a JavaScript object.
  4. Handle any potential errors by checking if there's an error object in the callback function, and if so, logging the error.
  5. If there are no errors, access and work with the parsed JSON data as needed within the callback function.