Get started

The example code in this cookbook relies on an example CoffeeStore database and an example Javascript application.

If you have not already done so, set up the access control cookbook environment by creating a database, an admin key, and a javascript application.

Create a CoffeeStore database

  1. Sign up for a free account at and log in to your account.

    The username and password you use when you create a Fauna account is the organizational account. This account has the admin role on every database in your Fauna space. Protect the organizational account password as you would any root-level password.

  2. Click CREATE DATABASE to create a database.

  3. Name your database a Name the CoffeeStore.

  4. Choose your preferred Region Group.

  5. Click the CREATE button.

    On successful creation, you’re directed to the Resources page of the CoffeeStore database.

Create an admin key

  1. Hover of the CoffeeStore database in the left-side navigation menu.

  2. Hover over the CoffeeStore database in the left-side navigation menu.

    Fauna displays a toolbar to the right of the database.

  3. Click the Manage Keys icon to open the Keys page.

  4. Click the CREATE KEY button.

    The Database name is already populated. The Admin Role is already populated.

  5. Enter coffee-admin for the Key Name.

  6. Click the SAVE button.

  7. Copy the KEY’S SECRET.

    At creation is the only time Fauna displays the secret field. The value in this field is equivalent to a password. Fauna cannot recover a secret that is discarded or lost. Copy and save the secret to a password manager or other safe location. Delete and replace keys or tokens for which you have lost the secret. If you no longer need a key or token, you should delete it.

Now, you have a key that can access and query Fauna Shell. A query made with this key has admin privileges on all the CoffeeStore database resources.

Create a Javascript application

Create a simple Javascript program that connects to Fauna with the coffee-admin key.

  1. Open a command prompt on your desktop.

  2. Verify that you have Node.js installed in your environment.

    which node

    If Node.js is not installed, take time to install it before moving onto the next step.

  3. Create a directory called coffeestore to hold your new application and then change into it.

    mkdir coffeestore
    cd coffeestore
  4. Install the fauna driver package:

    npm install fauna
  5. Create an coffeestore.mjs file.

    touch coffeestore.mjs
  6. Edit the coffeestore.mjs file and add the following code:

    import { Client, fql } from "fauna";
    // Configure your client
    const client = new Client();
    try {
      // Do something  here
    } catch (error) {
  7. Close and save the file

    node coffeestore.mjs

    When you run this command, you get an error. Later in this cookbook, you fix the error by providing a key.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email

Thank you for your feedback!