Skip to content
Sign upLog in

How to add comment system like of replit or youtube using nodejs and replit DB?

Profile icon

Pls help!

I thought of using MongoDB but it is not possible on replit as I downloaded it on my PC. I cannot import and run it on replit.

ENOUGH! Mongo! your ded!!
How to make a comment system, like of replit's or youtube.


You are viewing a single comment. View All
Profile icon


First off, getting the Repl_db package is easy as any module import, but with a slightly weirder module name:

const Database = require("@replit/database");

Now that we have a the module, we make an actual database using the module as a class. (All of this stuff I'm talking about can found in the docs)

const db = new Database();

setting a value is really easy, but you can only store strings, and you need to always provide a key. For your purposes, I'd probably just use an ever-increasing number to signify it's order in the comments or something.

db.set("<KEY>", "<VALUE>").then(() => {});

getting a value is just as easy

db.get("<KEY>").then((value) => {});

For your purposes though, I'd use the list function instead, which lists all of the currently stored keys, and then just get them all in a row.

db.list().then((keys) => {});

I'm gonna leave the rest up to your already competent hands.