In this JavaScript quickstart we will learn how to:

  • Retrieve database credentials
  • Install the JavaScript libSQL client
  • Connect to a remote Turso database
  • Execute a query using SQL

Retrieve database credentials

You will need an existing database to continue. If you don’t have one, create one.

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.

You will want to store these as environment variables.

Install @libsql/client

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

npm install @libsql/client

Initialize a new client

Next add your database URL and auth token:

import { createClient } from "@libsql/client";

export const turso = createClient({
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,

Execute a query using SQL

You can execute a SQL query against your existing database by calling execute():

await turso.execute("SELECT * FROM users");

If you need to use placeholders for values, you can do that:

await turso.execute({
  sql: "SELECT * FROM users WHERE id = ?",
  args: [1],