Reading Files in JS
Text File
fetch('file.txt')
.then(response => response.text())
.then(text => console.log(text))
// outputs the content of the text file
JSON File
fetch('file.json')
.then(response => response.json())
.then(jsonResponse => console.log(jsonResponse))
// outputs a javascript object from the parsed json
Top comments (0)