Deploying a web app built with Qwik and Turso on Netlify
Tags: netlify, turso, qwik, typescript
Published: 2023-07-05 14:46:13

---
title: Deploying a web app built with Qwik and Turso on Netlify
published: true
description: Here’s how you can deploy a website that stores its data in Turso on Netlify.
tags: netlify, turso, qwik, typescript
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e57a7qxn0ujqsovmgmdw.png
series: Everything Edge
canonical_url: https://blog.turso.tech/deploying-a-web-app-built-with-qwik-and-turso-on-netlify-e05898d54f53
# published_at: 2023-07-02 00:39 +0000
---

Unless we are tweaking around or playing with new tech for the sake of learning, most times we are working on products that we ultimately would like to share with the rest of the world. In such scenarios, services such as [Netlify](https://netlify.com) are among the household names when it comes to hosting projects for the web.

Netlify lets developers skip DevOps and set up projects globally in a production-ready, rollback-supporting, and scalable environment.

In this post, we are going to learn how to deploy a [Qwik](https://qwik.builder.io) application that stores its data in [Turso](https://turso.tech).

For an introduction to the stack being used in creating the project in this post, Qwik and Turso, you can refer to [this blog post](https://medium.com/chiselstrike/creating-a-newsletter-manager-with-turso-and-qwik-675e42126897), or the [Qwik docs](https://qwik.builder.io/) and an earlier blog post I wrote documenting [my early Turso impressions](https://jamesinkala.com/blog/early-impressions-of-turso-the-edge-database-from-chiselstrike/).

## Anatomy of the application

The app we are going to deploy on this post is a social link listing site (FindMeOn), we are specifically going to deploy this app on [Netlify’s edge functions](https://docs.netlify.com/edge-functions/overview/).

The social links listing app is made of two pages. The first contains a form that enables users to submit their user details, including the social media links they like to list as part of their profiles to the Turso database.

While the second page lists a person’s social links, which within the source code we are fetching the data from Turso, and listing it.

## Setting up Turso

The Turso setup for this app consists of a database and two tables, `users` and `lists`, the earlier containing user details such as a username, a name, and email, and the latter the social links URLs such as YouTube, Twitter, Linkedin, etc. [Visit the project’s README](https://github.com/turso-extended/app-find-me-on#setting-up-the-database) to get directions on how to set up Turso for this project.

The source code for this project can be found on [this GitHub repo](https://github.com/turso-extended/app-find-me-on).

## Deploying the app on Netlify

Netlify’s Edge Functions connect the Netlify platform and workflow with an open runtime standard at the network edge, which enables you to build fast, personalized web experiences with an ecosystem of development tools that has support for both TypeScript and JavaScript, since Netlify’s edge runtime runs on [deno](https://deno.land/).

With Netlify’s edge functions, you can modify network requests to localize content, serve relevant ads, authenticate visitors, A/B test content, etc.

Edge Functions also support a new generation of edge-first web frameworks that allow your entire app to run at the edge, dramatically increasing performance. This is true in the case of Qwik: the framework we’ve built the project being deployed on this post with.

So, Qwik bundles its production JavaScript files and makes them available on the edge, but to use the edge-specific context for localization, geolocation, content rewrite and more, we need to create and use custom-created edge functions, just as we’ll see in a short while.

Before proceeding with the next steps, make sure you have [signed up for a Netlify account](https://app.netlify.com/signup).

Authenticate to Netlify at the command-line level for global installation by running netlify login.

### Creating Netlify Edge functions

To create an edge function in Netlify, first, create a JavaScript/TypeScript file under the netlify/edge-functions directory within a project, exporting the function as a default.

Then, create a route path at which the functions should be accessed. There are two ways to go about creating a function’s path, the first being, exporting a config object containing the path to the function as its property.

```sh
export const config = { path: "/test" };
```
And, the second, involves adding the path to the function on the edge_functions section of Netlify’s configuration file netlify.toml on the root of the project. For a function file with the name test.js or test.ts, this is how you would set its path on the configuration file.

```toml
[[edge_functions]]
  path = "/test"
  function = "test"
```

Inside this project, we are fetching a localized greeting using a Netlify Edge function. To see the source code, open the [netlify/edge-functions/local-greeting.ts](https://github.com/turso-extended/app-find-me-on/blob/master/netlify/edge-functions/local-greeting.ts) file on the project’s repo.

In the source code, you can see that we are returning a localized greeting which is determined by checking the geolocation data of the source of the request. This piece of information is obtained by checking the [Netlify-specific Context object](https://docs.netlify.com/edge-functions/api/#netlify-specific-context-object).

### Deploying the app
There are two ways to deploy the app on Netlify, the first is by using the [netlify-cli](https://docs.netlify.com/cli/get-started/), and the second is through the Netlify dashboard. Here is a list of steps to follow for the latter.

- First, stage the project and push it to GitHub.

- Open your Netlify dashboard and add a new site.

![Open Netlify dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wno00yv3myg90q1jyky.png)

- On the next page, you’ll get to choose the Git client where your project is stored, in this case, GitHub. Choose it to proceed.

![Select Git client](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7k6n2ofzvu86145vajy.png)

- Next, search and pick your project’s repository.

![Pick project's repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wf2yyxnw7rwduty3k3j2.png)

- Set the site settings for your project, including selecting the production branch, build command, publish and base directory. For most frameworks, Netlify auto-detects and sets up default configuration.

![Configure Netlify hosting project settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k61llguq2u3jdozd7huy.png)

- One of the most important settings in this step is the setting up of the project’s environment variables. For this project, we need to set up the `VITE_TURSO_DB_URL` and `VITE_TURSO_DB_AUTH_TOKEN` environment variables which are the two credentials enabling us to communicate with the Turso database within this site.

![Add environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atu78onjduft2y6az69e.png)


- Finally, deploy the site.

![Deploy site](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y451194c7prq4041v2nx.png)


[Click here](https://findmeon.netlify.app/) to see the deployed version of this project on Netlify.

![Preview of FindMeOn as deployed on Netlify.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyc5maetcd370j8p5c29.png)

Preview of FindMeOn as deployed on Netlify.
So, this is how we can deploy Qwik apps on Netlify, while using Netlify Edge functions to utilize the edge-specific context.

To learn more about Netlify’s edge functions, [visit the official documentation](https://docs.netlify.com/edge-functions/overview/).

For a thorough guide on integrating Turso apps with Netlify, [visit Turso’s Netlify integration guide](https://docs.turso.tech/tutorials/netlify-setup-guide/).