Search code examples
node.jstypescriptdockersurrealdbsurrealdb-rpc

can't connect to local db for surrealdb


I have surrealdb running in docker like so

docker run --rm --pull always --name surrealdb -p 0.0.0.0:8000:8000 surrealdb/surrealdb:latest start --log debug --user root --pass root memory

and a node app running outside of docker, trying to connect to http://127.0.0.1:8000

it just stops on trying to use db.connect

try {
        console.log("database connecting")
        const test = await db.connect(`http://${host}:8000/rpc`, {
            versionCheck: true,
            database: "test",
            namespace: "test",
            auth: {
                username: "root",
                password: "root"
            }
        });
        console.log("Connected");
        console.log("Connected!");
        return db;
    } catch (err) {
        console.log("Failed to connect to SurrealDB:", err);
        throw err;
    } finally {
        console.log("db initialized");
    }

and it never reaches the finally.

I am using the latest sdk for node and the latest docker image. any ideas?

-- edit I can connect with the Surrealist client to the docker container db.


Solution

  • Alexander from SurrealDB here, I see you are trying to connect to localhost. For local development you need to pull from latest-dev you can see more in the docs here:

    https://surrealdb.com/docs/surrealdb/installation/running/docker#run-with-docker