Useful Bits of Code From Around The Web
Kyle Schwartz

Kyle Schwartz @kylejschwartz

About: Software Developer @ Filogix

Location:
Toronto, Canada
Joined:
Nov 26, 2019

Useful Bits of Code From Around The Web

Publish Date: Dec 21 '19
3 0

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
Enter fullscreen mode Exit fullscreen mode

JSON File

fetch('file.json')
  .then(response => response.json())
  .then(jsonResponse => console.log(jsonResponse))     
   // outputs a javascript object from the parsed json
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment