# Nuxt + Turso

> Set up Turso in your Nuxt project in minutes
> Canonical HTML: https://tursodb.cn/docs/sdk/ts/guides/nuxt/
> Upstream Source (MIT): https://docs.turso.tech/sdk/ts/guides/nuxt
> Language: en

---
![Nuxt banner](/images/turso-docs/guides/nuxt-banner.png)

Before you start, make sure you:

* [Install the Turso CLI](/docs/cli/installation/)
* [Sign up or login to Turso](/docs/cli/authentication/#signup)
* Have a Nuxt app — [learn more](https://nuxt.com/docs/getting-started/installation#new-project)

**1. Install the libSQL SDK**

Begin by installing the `@libsql/client` dependency in your project:



```bash npm
npm install @libsql/client
```

```bash pnpm
pnpm install @libsql/client
```

```bash yarn
yarn add @libsql/client
```

```bash deno
deno add npm:@libsql/client
```

**2. Configure database credentials**

Get the database URL:

```bash
turso db show --url <database-name>
```

Get the database authentication token:

```bash
turso db tokens create <database-name>
```

Assign credentials to the environment variables inside `.env`.

```bash
NUXT_TURSO_DATABASE_URL=
NUXT_TURSO_AUTH_TOKEN=
```

**3. Configure variables inside Nuxt's runtime config.**

```ts nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    turso: {
      databaseUrl: "",
      authToken: "",
    },
  },
});
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

Make sure that names of the keys in the `runtimeConfig` object match the names
of your environment variables. Read more about this
[here](https://nuxt.com/docs/guide/going-further/runtime-config).

</div></div>


**4. Configure libSQL Client.**

```ts server/utils/turso.ts
import { createClient } from "@libsql/client";
// You can optionally pass in the event to useRuntimeConfig
// import { H3Event } from "h3";

export function useTurso(/* event: H3Event */) {
  const { turso } = useRuntimeConfig(/* event */);

  return createClient({
    url: turso.databaseUrl,
    authToken: turso.authToken,
  });
}
```

**5. Execute SQL**

```ts server/api/items.get.ts
export default defineEventHandler(async (event) => {
  const client = useTurso(/* event */);
  const { rows } = await client.execute("select * from table_name");

  return {
    data: {
      items: rows,
    },
  };
});
```

## Examples

<div class="doc-cards">
<a class="doc-card" href="https://github.com/tursodatabase/examples/tree/master/app-top-web-frameworks" target="_blank" rel="noopener noreferrer"><div class="doc-card-title"><span>Website + App</span><span class="doc-card-arrow" aria-hidden="true">↗</span></div><p class="doc-card-desc">See the full source code</p></a>
</div>
