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