-1

So I was looking around but I couldn't find an answer for this. I'm not talking about reading them from a website, but when you type code in to the browsers console how can you make it read a certain local file and output its contents in the console?

SomeRandomGuy
  • 111
  • 1
  • 8
  • There's not much difference between executing JS on the browser's console and on a web page. If a web site can't do it, the console can't do it either. – JJJ Dec 30 '14 at 11:51
  • possible duplicate of [how to read text file in javascript](http://stackoverflow.com/questions/13709482/how-to-read-text-file-in-javascript) – wmock Dec 31 '14 at 05:08

1 Answers1

1

If you're using the browser environment, you have to first set up your HTML to read in the file via an input (with type=file). Once read in, you have manipulate that file using JavaScript. Take a look at this example: HTML5 Rocks - Reading Local files in JavaScript

If you're using the Node.js environment, there are built in functions that allow you to easily read files from your local environment. Take a look at this documentation: Node.js Documentation - fs.readFile

Hope this helps.

wmock
  • 5,382
  • 4
  • 40
  • 62