Set up a project using FSL and the Fauna CLI
Before you start
The tutorial assumes you have:
-
Completed the Quick start.
-
Not created a database or schemas for your app.
Set up a project
-
If you haven’t already, install the Fauna CLI:
npm install -g fauna-shell
-
Use
cloud-login
to log in to Fauna:fauna cloud-login
When prompted, enter:
-
Endpoint name:
cloud
(Press Enter)An endpoint defines the settings the CLI uses to run API requests against a Fauna account or database. See Endpoints.
-
Email address: The email address for your Fauna account.
-
Password: The password for your Fauna account.
-
Which endpoint would you like to set as default? The
cloud-*
endpoint for your preferred region group. For example, to use the US region group, usecloud-us
.
The command requires an email and password login. If you log in to the Fauna using GitHub or Netlify, you can enable email and password login using the Forgot Password workflow.
If successful, the command adds a related endpoint and secret to the
.fauna-shell
configuration file. -
-
If you haven’t already, create a directory for the project and navigate to it. In most cases, the directory also contains your app’s source code. For example:
mkdir <PROJECT_DIRECTORY> cd <PROJECT_DIRECTORY>
-
Create one or more databases for the app:
fauna create-database <DATABASE_NAME>
You can view the databases in the Fauna Dashboard.
-
Use
project init
to create a.fauna-project
file for the project:fauna project init
When prompted, enter:
-
A schema directory used to store FSL files. If the directory doesn’t exist, the command creates it.
-
A default environment name. See Environments.
-
A default endpoint to use for Fauna CLI commands.
-
A default database for Fauna CLI commands.
-
-
In the project’s schema directory, create and save one or more
.fsl
files.For example, you can create a
collections.fsl
file with the following FSL collection schema:collection Customer { name: String email: String index byEmail { terms [.email] } unique [.email] }
An FSL file can contain multiple schemas. You can use multiple FSL files to organize your schemas. There is no performance benefit to splitting FSL files or storing larger, individual files.
-
Use
schema push
to push the FSL schemas to Fauna:fauna schema push
Before pushing changes, the command displays a diff. If wanted, you can then accept or reject the changes.
-
Use
create-key
to create a key for one or more of your databases:fauna create-key <DATABASE_NAME> <ROLE>
To create a key for a top-level database, add
--environment=''
:fauna create-key --environment='' <DATABASE_NAME> <ROLE>
Your app can use the key’s secret to authenticate Fauna requests using a client driver or the Fauna Core HTTP API. You can also use the key to bootstrap a Fauna-based end-user authentication system.
Next steps
Congratulations! You’ve initialized a project and you’re ready to start building your app with Fauna.
To learn how to run queries from your app, check out the client driver docs or the Query HTTP API endpoint reference.
If you’d like to see a production-ready example, check out the Fauna JavaScript sample app on GitHub.
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!