How to access local instance of fauna with javascript

I have created a local fauna database and can access it through the shell. I have created Collections, Indexes and Queries and it all works well. I created the endpoint alias localhost

But I cannot figure out how to access the database through javascript

I have in my function

const faunadb = require("faunadb");
const client = new faunadb.Client({
    secret: process.env.FAUNADB_SECRET

It connects to the cloud database if I use the cloud secret, but if I change to the local secret, I get an Unauthorized Response

"name": "Unauthorized",
"message": "unauthorized. Check that endpoint, schema, port and secret are correct during client’s instantiation",
"description": "Unauthorized",

I have run

fauna list-endpoints

and the result is

localhost *

I have tried

fauna default-endpoint localhost

and the response is

Endpoint ‘localhost’ set as default endpoint.

But I still get the unauthorized error

What should I do?

I’ve solved it

const client = new faunadb.Client({
    secret: process.env.FAUNADB_SECRET,
    domain: 'localhost',
    port: 8443,
    scheme: 'http',

It seems endpoints are a red-herring

fauna list-endpoints is a command available when the fauna-shell NPM package is installed. It lists the configured endpoints in the ~/.fauna-shell INI file.

Those endpoint configurations have nothing to do with the configuration that your application might use unless you happen to use ~/.fauna-shell in your application… that doesn’t happen accidentally.

fauna-shell’s configuration is documented here: Configuration - Fauna Documentation

If you’re running the Fauna Dev Docker image, the required connection details are described here: Fauna Dev - Fauna Documentation

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.