Communicate between js and py

how do i communicate between js and py

basically i couldn’t find a way to do the javascript database stuff so i want to use the python database but i can’t get the data from python to javascript


from replit import db

db["key"] = "value"

# send db["key"] to script.js
// get db["key"] from python script


According to the official documentation, you need more JS than that (I assume you’re using NodeJS; for frontend JS I suggest creating a JSON API via Python Flask for your JS to access).

The official docs use this JS:

const Client = require("@replit/database");
const client = new Client();
await client.set("key", "value");
let key = await client.get("key");

I’m not too familiar with JS but I’d say line 1 for sure is absolutely necessary.

I also cannot say for certain that ReplDB will persist between NodeJS and Python. I don’t know exactly how it works.

1 Like

What if you used a DB proxy to link the JS db code to the same db as used in Python.
Will it work you think?

Should work although DB proxies are potentially unsafe. As long as the repl doesn’t need to be deployed a regular JSON file would be a much easier way to communicate.

1 Like