Reading JSON Files from local system with Node.js

Sanjay Singh
Oct 20, 2020

--

Read the JSON data from the file we can use the Node.js fs module.
There are two functions available in this module that we can use to read files from the file system: readFile and readFileSync

Example1-

const fs = require(‘fs’);

const fileUrl = new URL(‘file:///C:/Users/sanjsingh/Desktop/student.json’);
let data = fs.readFileSync(fileUrl);
let student = JSON.parse(data);
console.log(student);

--

--

Sanjay Singh
Sanjay Singh

Written by Sanjay Singh

Java, Spring Boot & Microservices developer Sharing knowledge, tutorials & coding tips on my Medium page. Follow me for insights & see story list section

No responses yet