Nuxt + Supabase = Technology Stack of Dreams 🚀
Tags: nuxt, javascript, vue, webdev
Published: 2023-06-26 07:32:02

I started my official developer career as a Frontend Developer few years ago. Then, I was developing the applications in Vue 2 (yes yes, dark times :D). I didn't have that much experience in backend development (more or less, my experience could be summarized that I knew how to run a simple Express server so not much).

At certain point, I realized that I need to add some backend knowledge to my technology stack in order to become a better developer in general and to allow me to build applications easily by myself. I started learning Node.js and Express but there were so many topics that I needed to cover like Database, Authentication, Cache, File Storage, Hosting, etc that I decided to give up and search for solutions that would enable me to have this functionality but in a easier way.

Then, I found out about [Supabase](https://supabase.com/)! And oh boy, Supabase basically solved all the issues I had back then as it allows to cover all these backend functionalities directly from the frontend in an easy and developer friendly way.

And then, I started diving more into Nuxt (especially most recent Nuxt 3) and oh boy (x2) I think I have found a stack of dreams 🎉

## What is Nuxt?

If you are not familiar with Nuxt yet, it is a framework that allows you to build your next Vue.js application with confidence. An open source framework under MIT license that makes web development simple and powerful.

![Nuxt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nygefgfnq8e5w1td9a9d.png)

It comes with several goodies out of the box like following:

* **Fast and Furious** - Optimized with code-splitting, tree-shaking, optimized cold-start, link prefetching, payload extraction, just to name a few. Fast by default so you can focus on building.
* **On-demand Rendering** - Decide what rendering strategy at the route level: SSR, SSG, CSR, ISR, ESR, SWR. Build any kind of website or web application with optimized performance in mind.
* **SEO & Web Vitals** - By leveraging server-side rendering, ESM format and optimized images, Nuxt websites are indexable by search engines while giving the feeling of an app to the end-users.
* **Plug & Play** - Unlock features by creating folders and files with the most intuitive directory structure made for developers and teams.
* **Automation** - Repetitive tasks are automated: auto-imports, code-splitting, typings, minification, bundling for production. and more.
* **Batteries Included** - Data fetching, state management, meta tags helpers, route guards, cookies, error handling, bundle analyzer and more.

And many more!

Take a look at the following video by Fireship about Nuxt:

{% embed https://www.youtube.com/watch?v=dCxSsr5xuL8 %}

*Interesting fact - in this video, one of the modules I created for Nuxt is featured - https://nuxt-medusa.vercel.app/*

So just to summarize, you get a lot of amazing features out of the box and future proof architecture that can scale easily!

## What is Supabase?

Supabase is an open source Firebase alternative.
Start your project with a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, Storage, and Vector embeddings.

![Supabase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i2ut4rmvbquef1926ak7.png)

* **Database** - Every project is a full Postgres database, the world's most trusted relational database.
* **Authentication** - Add user sign ups and logins, securing your data with Row Level Security.
* **Storage** - Store, organize, and serve large files. Any media, including videos and images.
* **Edge Functions** - Write custom code without deploying or scaling servers.
* **Realtime** - Create multiplayer experiences by sharing, broadcasting, and listening to changes from other clients or the Database.
* **Vector** - Integrate your favorite ML-models to store, index and search vector embeddings.

And many more!

Check out the following video for short intro to what Supabase is by Fireship

{% embed https://www.youtube.com/watch?v=zBZgdTb-dns %}

Next, let's take a look how we can use Supabase in Nuxt.


## Working with Supabase in Nuxt


![Nuxt Supabase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g158h085axekn6rjhd47.png)

First install the module like following:

```bash
yarn add --dev @nuxtjs/supabase
```

Then, register it in the `modules` array in `nuxt.config.ts`:

```ts
export default defineNuxtConfig({
  modules: ['@nuxtjs/supabase'],
})
```

Next, add the required environment variables:

```bash
SUPABASE_URL="https://example.supabase.co"
SUPABASE_KEY="<your_key>"
```

And that's it! You can now start using the module like following:

```vue
<script setup lang="ts">
const client = useSupabaseClient()
const { data: restaurant } = await useAsyncData('restaurant', async () => {
  const { data } = await client.from('restaurants').select('name, location').eq('name', 'My Restaurant Name').single()
  return data
})
</script>
```

The above example shows the usage of Supabase on the client side, but you can also use it very easily on the underlying server side (in Nitro) like explained [here](https://supabase.nuxtjs.org/usage/services/server-supabase-client) and like following:

First, let's create a new server endpoint 

```ts
import { serverSupabaseClient } from '#supabase/server'
export default eventHandler(async (event) => {
  const client = serverSupabaseClient(event)
  const { data } = await client.from('libraries').select()
  return { libraries: data }
})
```

And then, just call this endpoint from your frontend:

```vue
const fetchLibrary = async () => {
  const { libraries } = await $fetch('/api/libraries')
}
```

As you can see above, you can very easily work with Supabase in Nuxt in both client and server side!

## Why is Nuxt + Supabase a stack of dreams?

Nuxt gives you a framework that makes working with all types of web applications really easy. Thanks to Nitro presets, you can easily host your application on all modern hosting providers like Netlify, Vercel, Heroku, etc. It also comes with all the goodies that you may want in your app. This is currently my go to in terms for building new projects.

In terms of Supabase, it is basically a tool that allows frontend developers to build fullstack web applications very easily without extensive backend knowledge. 

What else you would want?

And what's better, both these tools are Open Source so you can use them for free, host them easily, and utilize the whole bunch of community modules and plugins!

Check out the following [demo](
https://n3-supabase.netlify.app/) application of Nuxt & Supabase made by @atinux 🚀

{% embed https://www.youtube.com/watch?v=jIyiRT6zT8Q %}

## Summary

And that's it! I hope that after reading this article I made some interesting points that would convince you why I think that Nuxt & Supabase is a perfect technology stack of dreams! Use it to build your next projects and let me know about the result! ⚡️