Ask coding questions

← Back to all posts
Use Javascript to open a directory?
isaiah08 (88)

How would I use JS to open testing.txt and read what is in it?
(I am using Javascript by having a .html file and using a <script> tag.)

Answered by Coder100 (19280) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (19280)

Easy! Make an HTTP request! (Note you won't be able to write)

Coder100 (19280)

nooo you can't use it like that @isaiah08

Coder100 (19280)

ugggh ig you don't know what promises are. You see, it takes some time to load the file, and JS doesn't like that, so it returns something called a promise, which will get resolved later on. What you want is:

@isaiah08

Also, you forgot to set the type of the output lol

mamamia5x (84)

You would use the Javascript FS module, but it can't be used in an HTML, CSS, JS repl, it'll have to be used on a NODEJS repl

Coder100 (19280)

@mamamia5x no they don't, they can just make an HTTP request

RohilPatel (1597)

Ur right j*r** (not bad word, his name) @Coder100