Before we can start building with Supabase, we need to set up our local development environment. This chapter walks through installing the necessary tools, scaffolding the project structure, and installing the Supabase JavaScript client library. By the end of this chapter, you will have a working project ready to connect to Supabase.
You need three things installed on your machine:
node -v and npm -v in your terminal.There are two ways to use the Supabase client library in your project.
For projects using a bundler like Vite, Webpack, or Parcel, install the package as a dependency:
npm init -y
npm install @supabase/supabase-js
The npm init -y command creates a package.json file with default values. The npm install command downloads the Supabase client and all its dependencies into the node_modules folder and adds it to package.json.
For simple HTML projects without a bundler, use a script tag:
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
This loads the Supabase client directly in the browser. The library is available globally under supabase namespace. You access it as supabase.createClient() instead of using ES module imports.
Your Supabase project URL and anon key should never be hard-coded in your source files. Create a .env file in your project root to store these values:
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
If you are using Vite, environment variables must be prefixed with VITE_ to be exposed to the client. For other setups, use dotenv or load the variables manually. Add .env to your .gitignore file to avoid committing secrets.
Create the following folder and file structure for this tutorial:
supabase-tutorial/
index.html
app.js
.env
.gitignore
package.json
chapters/
1-introduction.html
2-setup-download.html
3-setup-account.html
4-auth.html
...
The index.html file serves as the main entry point. The app.js file holds our JavaScript logic. The chapters/ folder contains individual chapter files. The .gitignore file should include node_modules and .env.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Supabase Tutorial</title>
</head>
<body>
<h1>Supabase Tutorial</h1>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="app.js"></script>
</body>
</html>
const supabaseUrl = 'https://your-project.supabase.co'
const supabaseAnonKey = 'your-anon-key-here'
const supabase = supabase.createClient(supabaseUrl, supabaseAnonKey)
console.log('Supabase client initialized:', supabase)
Notice the use of supabase.createClient() (not createClient) because the CDN version exposes the library under the global supabase namespace.
package.json using npm init -y and install the Supabase client with npm install @supabase/supabase-js. Create index.html and app.js with the content shown above. Verify the client loads by opening the HTML file in a browser and checking the console.