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
-
Sign up for a free account at https://dashboard.fauna.com/register and log in to your account.
The
username
andpassword
you use when you create a Fauna account is the organizational account. This account has theadmin
role on every database in your Fauna space. Protect the organizational accountpassword
as you would any root-level password. -
Click CREATE DATABASE to create a database.
-
Name your database a Name the
CoffeeStore
. -
Choose your preferred Region Group.
-
Click the CREATE button.
On successful creation, you’re directed to the Resources page of the CoffeeStore database.
Create an admin key
-
Hover of the CoffeeStore database in the left-side navigation menu.
-
Hover over the CoffeeStore database in the left-side navigation menu.
Fauna displays a toolbar to the right of the database.
-
Click the Manage Keys icon to open the Keys page.
-
Click the CREATE KEY button.
The Database name is already populated. The Admin Role is already populated.
-
Enter
coffee-admin
for the Key Name. -
Click the SAVE button.
-
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.
-
Open a command prompt on your desktop.
-
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.
-
Create a directory called
coffeestore
to hold your new application and then change into it.mkdir coffeestore cd coffeestore
-
Install the fauna driver package:
npm install fauna
-
Create an
coffeestore.mjs
file.touch coffeestore.mjs
-
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) { console.log(error) }
-
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 docs@fauna.com
Thank you for your feedback!