Ask coding questions

← Back to all posts
How Do I Access Other Repl.It Databases From Different Repls?
Ste942 (0)

I just want to get one value for one key. I am programming in Node.js and have little to no experience with external APIs, but I tried played around with the database URL using a API testing tool (ReqBin) and wasn't able to accomplish anything.

Am I supposed to use the replit-database package to access it or do a GET request to pull data from it. Any help would be appreciated.

Answered by RayhanADev (2606) [earned 5 cycles]
View Answer
RayhanADev (2606)

Heylo @Ste942

There’s a flaw in how they coded ReplDB and integrated it with the Repl so I’ll make it short:
1. Open the Repl which DB you want to use
2. Open the Shell by pressing Ctrl+Shift+S
3. In the shell type printenv. You will see a lotta stuff pop up. Look for the variable named REPLIT_DB_URL. Note that, copy it, whatever
4. In the other Repl type create a client like normal except with ONE small change:

const client = new Client(LINK YOU COPIED FROM BEFORE)

and now it should work 😊! Let me know how it goes!

bigboyyyyyyyy69 (5)

@RayhanADev I see you provided an answer but how could I do this in python?

RayhanADev (2606)

@bigboyyyyyyyy69 Hiya! Just click the tab on the left with the database symbol and it should show a line similar to the one above. Insert that and follow the same steps :).

bigboyyyyyyyy69 (5)

@RayhanADev oh I can only see how to do it in the native db not with a link..

RayhanADev (2606)

@bigboyyyyyyyy69 pass in the link as a parameter when creating the db :)

bigboyyyyyyyy69 (5)

@RayhanADev but u dont create the db in python.. right? could you send an example pls..

RayhanADev (2606)

@bigboyyyyyyyy69 yep! I had to dig around Github and find the database module. Here's what you do:

from replit import db
db.db_url = "your-db-url-here"
bigboyyyyyyyy69 (5)

@RayhanADev Also I just thought of something: Changing the value "REPLIT_DB_URL" with os or smth.. is that even possible? Just curious lol

RayhanADev (2606)

@bigboyyyyyyyy69 hmm, I do not know ƪ(˘⌣˘)ʃ. Try it and lmk how it goes :D

Coder100 (18902)

Well I just want to say you can't.

The database URL will change so you will have to regenerate each time.
Anyways, I have an option so you can pass the url when making a client:

const client = require("@replit/database");
const DB = new client("[INSERT-URL-HERE]");

and to find that url, just do:


in the repl of your choice.

Ste942 (0)

@Coder100 Thanks. Again, I am a beginner so I apologize if I am not following here, but is the regenerating URL the issue?

Also, do you happen to know how often the URLs regenerate? (every hour, every day, every month, etc)

Efish1824 (10)

You can't. Just make the first repl with a database a file in the second repl.

Ste942 (0)

@Efish1824 I don't know if its not possible, since on the Database page on the docs, ( the very bottom section has a tiny place where it suggests it is possible.