Learn to Code via Tutorials on Repl.it!

← Back to all posts
How To Make And USe Ur Own Database (NODE.JS)
GatewayDuckYT (60)

Far warnings having the folder name or file name with db, data, database etc will not always work
Far Warning As far as I know this does not work on python thou i am making api for html

Have more info or have questions ask below

Protip: I use the npm package simple-json-db
To set this up do this in the shell
npm i simple-json-db

In your code just require it like so

const JSONdb = require('simple-json-db');
//make a new database path folders must be there
const db = new JSONdb('/path/to/your/database.json');

Its as easy as that for this Tutorial i will be using this file tree line

  • root
    • index.js
    • info.json

So My setup code would be

const JSONdb = require('simple-json-db');
const db = new JSONdb('./info.json');

Simple use

all i need to do to add a value is

db.set('key', 'value')


    "key": "value"

You can also set arrays

db.set('key', ["gamer", "time"])


    "key": ["gamer", "Time"]

And as far as i know u can set json

db.set('key', {gamer: "me", upvote: true})


    "key": {
      "gamer": "me",
      "upvote": "true"

Getting Value

Getting values are easy
u can do

//=> value

also getting arrays and json from them is also easy

//=> ["gamer", "Time"]
//=>{ "gamer": "me", "upvote": "true"}
var x = db.get('key')
//=> me

You can also use this to see if a value even is there

//=> true
//=> false

and last of all u can delete values

    "key": "i am here"


EpicGamer007 (1751)

file databases will not work on replit. this means .db files and json file storage will not work

GatewayDuckYT (60)

@EpicGamer007 no sir do not use .db
And what the heck are u talking about i use them daily on my repl

EpicGamer007 (1751)

@GatewayDuckYT can you send me an example? I am 100% certain your file saving sometimes get rolled back.