Fauna Add-on for Netlify
The Fauna Add-on for Netlify makes it easy to use Fauna as the database for your Netlify sites and functions.
Overview
Fauna is an ideal companion for your serverless web applications hosted by Netlify, an excellent choice for web site hosting and development.
The Fauna pricing model provides a generous free plan, which makes it ideal for developing your web application. You only pay when you exceed the thresholds for free service. See the pricing page for details.
Fauna multitenancy features make it easy to create and manage per-client databases, which simplifies your application development considerably. Create a database for a client, and create and store a key for that database. When the client logs in, use the stored key to access the client database. Fauna is accessed using HTTPS and there is no cross-database data contamination.
When you setup the Fauna Add-on for Netlify, a Netlify database is
created in Fauna, an access token is created and stored in a Netlify
environment variable, and the
JavaScript
driver is installed.
How to use the Fauna Add-on for Netlify
It only takes a few minutes to get setup.
-
Sign up for a Netlify account
You can skip this step if you already have a Netlify account.
-
Install the Netlify command-line tool
You can skip this step if you have previously installed
netlify-cli
.In a terminal, run the following command:
npm i netlify-cli -g
-
Create a folder for your Netlify project
If you already have a Netlify project created,
cd
into that folder in your terminal, then skip to the next step.In your terminal, run the following commands:
mkdir my_project cd my_project
-
Initialize your Netlify project
If you have already initialized your Netlify project, skip to the next step.
In your terminal, run the following command:
netlify init
-
Add the Fauna Add-on for Netlify
In your terminal, run the following command:
netlify addons:create fauna
-
Authenticate the Add-on
In your terminal, run the following command:
netlify addons:auth fauna
This step prompts you to sign up with Fauna or login if you already have an account. After logging in, you are prompted to name your database and import it into your account. This allows you to interact with your database directly using the Fauna Dashboard.
The database created for your project gets a generated name, which
looks like c7d7da35-e79a-4cad-88cd-83a152b50793 . You can freely
rename the database, using the Fauna Dashboard or fauna-shell ,
to make it easier to identify to which project it belongs.
|
Netlify environment variables
After the Fauna Add-on for Netlify is setup, access tokens are available in the following Netlify environment variables:
-
FAUNADB_ADMIN_SECRET
: A secret with theadmin role
. This secret grants full access to parent of the created database. -
FAUNADB_SERVER_SECRET
: A secret with theserver role
. This secret grants full access to the parent of the created database, but none of its child databases. -
FAUNADB_CLIENT_SECRET
: A secret with theclient role
. This secret grants access only to documents with thepublic
permission in the parent of the created database. Typically, this means no access.
Next step
The next step is to build your web application or microservice. See the Netlify documentation for help there.
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!