This is a companion repository to the tutorial: "Quickstart for using Couchbase with Netlify" at developer.couchbase.com, which aims to get you up and running with Couchbase on Netlify
To run this prebuilt project, you will need:
- A Couchbase Capella account (Get started for free with a trial database account)
- A Netlify account (Get started for free by signing in with your GitHub account)
- A GitHub account
- Netlify CLI
- Node.js 16+ setup and work with the CLI of your choice.
We've included a .env.example
file with blank values for you to copy into a file called .env
and fill in the values.
COUCHBASE_USERNAME
- The username of an authorized user on your cluster. Follow these instructions to create database credentials on CapellaCOUCHBASE_PASSWORD
- The password that corresponds to the user specified aboveCOUCHBASE_ENDPOINT
- The Couchbase endpoint to connect to. Use the endpoint of your Couchbase Capella database (formatted likecb.<xxxxxx>.cloud.couchbase.com
)COUCHBASE_BUCKET
- The bucket you'd like to connect to. Set this totravel-sample
for this tutorial.
The main tutorial will walk you through the process of building a web application with Netlify Functions and Capella, but here we'll focus on just cloning and running this example repo.
Clone the source code:
git clone https://github.com/couchbase-examples/netlify-tutorial.git
Install required dependencies:
npm install
You'll have to manually create a database and import the travel-sample
data.
In this section, we will walk through how to setup Couchbase Capella with sample data called travel-sample
. If you do not have a Couchbase Capella account, follow the directions in this blog article. Please ensure you can sign into your Couchbase Capella account before continuing.
We need to set up a Couchbase Capella database with the sample data and configure the internet and user settings to allow Netlify Functions to access the database.
Create your Couchbase Capella database and set up the sample data.
- On the Couchbase Capella console, create a new database and navigate to it.
- Click Import Data under the Start tab
- Import the Travel Sample dataset
Next we need to set up internet settings to allow connections from all IP addresses. This is required for Netlify Functions to access the database for the purpose of this tutorial.
- Navigate to the
Settings
tab on the database page. - Navigate to
Networking > Internet
on the sidebar
NOTE: We will use the connection string displayed on this screen later in our code that will allow us to configure how to connect to Couchbase Capella via the Couchbase NodeJS SDK. Please copy this information and put it somewhere where you can access it later in the tutorial to save yourself from returning to this screen.
- Click
Add allowed IP
- Allowlist
0.0.0.0/0
and save
Next, we will need to create a user account that can be used to access the database from our Serverless Function.
- Confirm that you are on the
Settings
tab. - Navigate to
Security > Database Access
on the sidebar - Enter a memorable name and password as we'll need that later.
- Select
travel-sample
for Bucket - Select
All Scopes
for Scopes - Select
Read/Write
for Access
You should now have a Couchbase Capella database, the travel-sample
data loaded, network access configured, and a user account to access the data setup.
Now we're ready to run our application:
netlify dev
If everything is configured properly, you should be able to navigate to localhost:8888
to see the example application.