Nuxt banner

Before you start, make sure you:

1

Install the libSQL SDK

npm install @libsql/client
2

Configure database credentials

Get the database URL.

turso db show --url <database-name>

Get the database authentication token.

turso db tokens create <database-name>

Assign credentials to the environment variables inside .env.

NUXT_TURSO_DATABASE_URL=<"..."
NUXT_TURSO_AUTH_TOKEN="..."
3

Configure variables inside Nuxt's runTime config.

nuxt.config.js
export default defineNuxtConfig({
  runtimeConfig: {
    turso: {
      dbUrl: "",
      dbAuthToken: "",
    },
  },
});
4

Configure LibSQL Client.

server/utils/turso.ts
import { createClient } from "@libsql/client";

export const turso = createClient({
  url: tursoConfig.dbUrl,
  authToken: tursoConfig.dbAuthToken,
});
5

Execute SQL

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

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

Examples