Read/Write JSON Files with Node.js

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • See the written version of this tutorial for links to prerequisites and related tutorials: heynode.com/tu...
    When you want to store data between server restarts with Node, JSON files are a simple and convenient choice. Whether you are reading a config file or persisting data for your application, Node has some built-in utilities that make it easy to read and write JSON files. Using JSON files in your app can be a useful way to persist data. We will look at a few different methods for working with JSON files.
    In this tutorial we'll:
    - Read JSON data from disk
    - Learn to use fs module to interact with the filesystem
    - Persist data to a JSON file
    - Use JSON.parse and JSON.stringify to convert data to and from JSON format
    Heynode.com: The best online Node.js courses and tutorials to help you solve hard problems fast.

ความคิดเห็น • 76

  • @bobmonsour
    @bobmonsour 3 หลายเดือนก่อน

    An excellent tutorial. And it's exactly what I was looking for as I am about to embark on writing a simple editor for a very specific json file. I will be the sole user and the file is not terribly large, so I am not concerned about multiple users editing the file at the same time. And it's great that you have a written version of this for reference. Thank you!

  • @mohdhussain5918
    @mohdhussain5918 2 ปีที่แล้ว +2

    Bro.... What a teaching skill.... Cleared all doubts in single video👍

  • @dhruvsanmotra6187
    @dhruvsanmotra6187 2 ปีที่แล้ว

    I was searching for json read write whole day then found your vedio.......
    Just 10 min but explained every thing😍

  • @prathmeshkalehere
    @prathmeshkalehere 5 หลายเดือนก่อน

    Your voice is sooo soothing

    • @prathmeshkalehere
      @prathmeshkalehere 5 หลายเดือนก่อน

      but vs code white theme is killing me

  • @agustinpena2752
    @agustinpena2752 ปีที่แล้ว

    Thank you for the tutorial, it's very informative ))) Please consider using your IDE with a dark theme when making your videos, it's hard to watch this at night 😅

  • @domaincontroller
    @domaincontroller 3 ปีที่แล้ว

    Finally after zapping over 2 tons of inconsistent fs module tutorials, i got he good one ! Damn it

  • @mateonavarrette4864
    @mateonavarrette4864 2 ปีที่แล้ว +1

    Very clearly explained, thanks for the help! I had trouble trying to push a new item into an array in a json document, and this cleared some things up for me

    • @gethermedel3620
      @gethermedel3620 ปีที่แล้ว

      what happens if you actually have 2 or 3 json objects in the file? how do you handle to update them? can you share it with me?

  • @hatdoggo8824
    @hatdoggo8824 4 ปีที่แล้ว +6

    Best tutorial ever.. Keep up the great work!

  • @pileydes
    @pileydes หลายเดือนก่อน

    Thank you for this great video.

  • @kostiantynkarzhanov9216
    @kostiantynkarzhanov9216 11 หลายเดือนก่อน

    Very good tutorial, consice and easy to understand! Thank you so much! 💛

  • @kentang9486
    @kentang9486 3 ปีที่แล้ว +2

    You explained really clearly. Nice tutorial. Great work!

  • @xef6283
    @xef6283 3 ปีที่แล้ว

    I've been wandering for hours now, looking for JSON read/file help in Node.js (newbie here). Loading JSON faking a web request/response just wasn''t for me and for the project I'm currently on, yet it seemed the only, or at least the "way more popular" way (why in the world? you already possess the *.json file locally... just wondering). I can't really describe how big is my wish to say "Thank you". Thank you for existing, this video is exactly what I needed.

  • @Cessarini1
    @Cessarini1 3 ปีที่แล้ว +1

    Hey, just want to thank you for making this video tutorial. Cheers

  • @DirtMankee
    @DirtMankee ปีที่แล้ว

    Thanks for the wonderful explanation. Helped me alot.

  • @sarangjaiswal
    @sarangjaiswal 4 ปีที่แล้ว +2

    Thanks! Nice explaination

  • @sqb8980
    @sqb8980 2 ปีที่แล้ว

    Underrated channel

  • @anitahemrajani1373
    @anitahemrajani1373 3 ปีที่แล้ว

    Very clearly and simply explained. Thankyou.

  • @emadroghani1856
    @emadroghani1856 3 ปีที่แล้ว

    Super easy example help nobody in practice

  • @dragunwf
    @dragunwf 2 ปีที่แล้ว

    You explained it quite clearly, thank you!

  • @ashishnayak2666
    @ashishnayak2666 3 ปีที่แล้ว

    Very nice example

  • @microfox_hd3042
    @microfox_hd3042 3 ปีที่แล้ว +1

    Thanks amazing tutorial gained a new sub

    • @heynode
      @heynode  3 ปีที่แล้ว

      Thanks for the sub!

  • @pradipspeaks9395
    @pradipspeaks9395 ปีที่แล้ว

    Very nice.
    Please make us learn the same thing in Typescript as well 🙏

  • @septimusforster
    @septimusforster 8 หลายเดือนก่อน

    Splendid stuff.

  • @thed100mechanic
    @thed100mechanic 4 ปีที่แล้ว +1

    Really nice tutorial, thank you!

  • @DerCooleVonDem
    @DerCooleVonDem 3 ปีที่แล้ว

    Best Tutorial ever MADE

  • @omarsherif6198
    @omarsherif6198 3 ปีที่แล้ว

    Nice tutorial, interested to watch you covering other topics too

    • @heynode
      @heynode  3 ปีที่แล้ว

      Hey thanks Omar. What other topics in particular would you like to see?

    • @gethermedel3620
      @gethermedel3620 ปีที่แล้ว

      @@heynode how do you actually handle this if you have 2 or more json object?

  • @ahmedstutorials3357
    @ahmedstutorials3357 3 ปีที่แล้ว

    Thank you bro, helped me alot.

  • @navajyothiboppidi6410
    @navajyothiboppidi6410 3 ปีที่แล้ว

    very good information. Thanks for sharing.

  • @exclusivestudios
    @exclusivestudios 2 ปีที่แล้ว

    Thank you very much!

  • @willmcdonnell287
    @willmcdonnell287 3 ปีที่แล้ว

    great video. Thank you!

  • @dawsonhorn5290
    @dawsonhorn5290 3 ปีที่แล้ว

    Great tutorial. Thanks a ton.

  • @kumar_sanjeevdutta1069
    @kumar_sanjeevdutta1069 9 หลายเดือนก่อน

    Great and just great

  • @PlayboyPrime
    @PlayboyPrime 2 ปีที่แล้ว

    Thanks for your help :)

  •  3 ปีที่แล้ว

    Great video, thanks!

  • @alexandregilardeau870
    @alexandregilardeau870 2 ปีที่แล้ว

    thank you help a lot !

  • @domaincontroller
    @domaincontroller 3 ปีที่แล้ว +1

    07:00 fs.writeFile

  • @user-gd4qc4bz3f
    @user-gd4qc4bz3f 9 ชั่วโมงที่ผ่านมา

    감사합니당

  • @riigel
    @riigel 2 ปีที่แล้ว

    You're the best!

  • @NotoriousArnav
    @NotoriousArnav 2 ปีที่แล้ว

    Nice tutorial, just hated the light theme

  • @ABUTAHER-wg7gz
    @ABUTAHER-wg7gz 2 ปีที่แล้ว

    Tutorial starting time show require file then without require system, you are show data??

  • @Tiberiumgod
    @Tiberiumgod 2 ปีที่แล้ว

    How can we parse chunks as valid JSON? What if we have a huge json file and want to make some logic for chunks?

  • @wivon
    @wivon 2 ปีที่แล้ว

    Good video ! (why you use light mode? lmao )

  • @_ShaikhMohammedFazleHaqueAmin
    @_ShaikhMohammedFazleHaqueAmin ปีที่แล้ว

    i am having problem in reading and writing it is saying file not exists only way i was able to read it using require() can any one help me

  • @anuanusha73
    @anuanusha73 2 ปีที่แล้ว

    may i know how to convert a text file to json in nodejs

  • @zaahidfarooq
    @zaahidfarooq 3 ปีที่แล้ว

    How we can add data in json file without erasing/deleting the exist data on the json file

  • @ivgilevinsonkaslasi5778
    @ivgilevinsonkaslasi5778 3 ปีที่แล้ว

    good job!

  • @alfonstabz9741
    @alfonstabz9741 3 ปีที่แล้ว

    i need to put a type: module in json file but don't know how to do it

  • @bestapps4709
    @bestapps4709 ปีที่แล้ว

    Can this NODE be used like js, without libraries buddy?

  • @shubhamambhore5707
    @shubhamambhore5707 3 ปีที่แล้ว

    🔥🔥🔥🔥 Thanks

  • @kurtismelkisoft4309
    @kurtismelkisoft4309 ปีที่แล้ว

    tout ça c'est beau mais comment on fait pour utiliser les données dans un vrai programme javascript?

  • @falecommoraes
    @falecommoraes ปีที่แล้ว

    This error - ReferenceError: JSONReader is not defined at Object. - on Update code. :(

    • @eojthebrave
      @eojthebrave ปีที่แล้ว +1

      The function jsonReader() was defined earlier in the video at th-cam.com/video/HrjC6RwEpt0/w-d-xo.html, you'll need to make sure that function exists before writing the update code. Hope that helps.

  • @mucahitkaraoglan224
    @mucahitkaraoglan224 3 ปีที่แล้ว

    perfect

  • @IslamTheRightWay10
    @IslamTheRightWay10 ปีที่แล้ว

    is fetch() not a good move to use to get data from json file?

    • @eojthebrave
      @eojthebrave ปีที่แล้ว +1

      I think you would want to use fetch() if the .json file was served over HTTP and you had to request it from another server. And fs.readFile for files on the same filesystem.

  • @Cdswjp
    @Cdswjp 3 ปีที่แล้ว

    does fs.readFile always read the current state of the file BECAUSE it's an async function?... or are those 2 separate pieces of information?

    • @eojthebrave
      @eojthebrave 3 ปีที่แล้ว

      Two different bits of information. The important piece here is that using something like `require('./file.json')` loads the file's content into the node.js memory cache and it's possible that subsequent calls will return the cached result instead of reading the file from disk again. `fs.readFile` will always ready the file from disk whenever it is executed.

  • @dailymeow3283
    @dailymeow3283 3 ปีที่แล้ว

    Hey thank you for these videos, is there a function i could write to send json data to my email ?

    • @eojthebrave
      @eojthebrave 3 ปีที่แล้ว +1

      I've not done it myself, but it looks like you could accomplish this with nodemailer.com/usage/. Using something like the jsonReader() function in this tutorial, and then instead of console.log() to output the data write a function that uses ndoemailer to send an email that contains the data you've read in.

    • @dailymeow3283
      @dailymeow3283 3 ปีที่แล้ว

      @@eojthebrave thanks Joe

    • @dailymeow3283
      @dailymeow3283 2 ปีที่แล้ว

      @An A Count lol

  • @mahendrasinhgohil44
    @mahendrasinhgohil44 3 ปีที่แล้ว

    How to do same with react native?

  • @locksawwatch1084
    @locksawwatch1084 2 ปีที่แล้ว

    ReferenceError: jsonReader is not defined
    EDIT: Nvm i just looked at tutorial on google(your video on website)

  • @bibekgurung9075
    @bibekgurung9075 2 ปีที่แล้ว

    How do you do this on react?

  • @swarnavasireddy6150
    @swarnavasireddy6150 3 ปีที่แล้ว

    But on build this is not working

  • @jatinsinghal6438
    @jatinsinghal6438 2 ปีที่แล้ว

    i am not able to get address

  • @nicolaslegrand3367
    @nicolaslegrand3367 3 ปีที่แล้ว

    good game

  • @rojka-_-
    @rojka-_- ปีที่แล้ว +1

    tip, use dark mode

    • @oBerrie
      @oBerrie 11 หลายเดือนก่อน

      Yeah lol

  • @ABUTAHER-wg7gz
    @ABUTAHER-wg7gz 2 ปีที่แล้ว

    are you kiding with public?

  • @mikhailwebb8377
    @mikhailwebb8377 ปีที่แล้ว

    I keep getting an error. Javascript is possible the worst programming language.