How to Read and Write to Text Files in JavaScript

preview_player
Показать описание
Hello everyone, welcome to SteamCode! In this video, I will show you how to read and write to text files using JavaScript. If you enjoy the video, please like and subscribe, and if you have any questions, do not hesitate to leave them in the comment section below.

Рекомендации по теме
Комментарии
Автор

No waste of time, no bullsht, just direct explanation of point. Thank you.

isimlikullanc
Автор

Hi!
Sorry, but this is NOT Javascript! This is Node.js. I'm looking for a vanilla javascript solution. Do you have a solution for that?

nyitigvilaga
Автор

Thank you for a short and simple tutorial.. I am new subscriber to your channel🙂

Jandhyalas
Автор

Thanks a million! This is a great tutorial!

shanermahmud
Автор

Misleading. The title should have Node. People creating a client side app will get an error as "require" is not defined! As well as those with no node installed on their machine

mooseminddayan
Автор

thank you usince morning was getting wrong and confusing information but now im oky ..thank you so much

uxheiby
Автор

can we add some text at some specific point in the file?
like on index 3??

bhaveshgudlani
Автор

How do you read and write files with Javascript without Node.js?

SuperYtc
Автор

Thanks @SteamCode for great content.
I had one question though. Recently I was trying to read cert files using similar approach, although when the react project was up on web-dev-server, I was not able to read those files. Is there any restriction with this approach such that when the project is up on some server wr can't read those files?

shardulsant
Автор

i need help on how one can read multiple files of same type in a folder then after reading them then create one file which comprises of the data which have been read

mambogeezy
Автор

I'm using React Nodejs, and I'm getting this error from trying to require "fs", : "ERROR in ./src/App.js 9:11-24
Module not found: Error: Can't resolve 'fs' in '/React/server-test/src' webpack compiled with 1 error and 1 warning"
Why is this happening?

horridparlor
Автор

It seems fs.writeFile() and fs.appendFile() perform the same operation? You overwrote the readFile with writeFile then edited with appendFile. Could we not just continually overwrite the existing file and forget appendFile altogether or is there some other benefits I don’t see?

dylan
Автор

Hey, great tutorial. I was wondering if anyone knows how to save the contents of a file as a variable? I tried saving a content variable as data in the block and it didn’t work. I also tried making as a list and adding to it each iteration but that also didn’t work, and no form of just using the data variable seems to do anything. Sorry if this is a rly simple request an I just don’t see it, I’m new with js so any help is appreciated!

Cuber
Автор

but how do I put the contents of data in a variable outside of "fs.readfile"?
in short, I want to read a file, work with it's contents within my program, then save the results in another .txt

kozkiroify
Автор

I'm having some issues running node with bash terminal. Following your code on my mac doesn't seem to work, but on my friends windows it works with powershell. Do you know anyway around this?

johnschaefer
Автор

Thanks for this information bro, can we use switch and case to add and read contents on the text file ?
ex: press 1 to add content
press 2 to view content
press 0 to exit

abhijithtgcse
Автор

how do i get the data out so i can use it?

kezzaman
Автор

Thanks for this! Is console.err a thing or was that a typo for console.error(err)?

jamesharland
Автор

I'm trying to load a text file so I can use the content as values to my variables. I've tried many approaches, but I think this one is the simplest. However, every time I apply this code in my editor I run into the same problem:

( Error: ENOENT: no such file or
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: the_to_my_file_here....

I tried to change the extension of my text file but it didn't work, I also tried to change the location of my script and the text file, it didn't work also.
I am using :
---VS code
---JavaScript
---file.txt (also tried .csv)
---windows 11
I'm looking forward for your reply.

younesqara
Автор

if in file.txt new row, why get to string bro
example in the file txt is

beginer
medium
low
higt

i get to variable string
what code in java doctype script

var dat01, dat02, dat03, dat04;

load file and maybe like this
dat01 this is beginer
dat02 this is medium
thx bro

ekoking