Ask coding questions

← Back to all posts
creating and reading JSON files
Nanowrimoijk (58)

wondering how to set up a JSON database and how to read it in JS

Answered by heyitsmarcus (342) [earned 5 cycles]
View Answer
heyitsmarcus (342)

First off, great question!

I believe you are talking about NodeJS, just given some of your repls in your profile, so I'm going to show a solution that I use (and love) in NodeJS.

A great JSON database is NeDB which makes it a piece of cake to work with JSON data. It is almost a duplicate of MongoDB which means that it is a NoSQL database. You can save, load, query, etc. all kinds of data. Here's a simple example of storing some JSON data into the database and then retrieving it:

Also, here is a great article on more NeDB functionality (and where I copied some of the code out of because I'm lazy):

I really hope this helps!

If this helped solve your problem, please consider upvoting and marking my answer as the accepted answer to close this question. I'll continue to answer any questions you might have, though.