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.

You will want to store these as environment variables.

Install @libsql/client

First begin by installing the @libsql/client:

npm install @libsql/client

Initialize a new client

Next add your database URL and auth token:

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

const client = createClient({
  url: "libsql://...",
  authToken: "...",

You can also connect to a local SQLite file by passing file: instead of a URL when using Node.js, learn more.


Execute a query using SQL

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

const result = await client.execute("SELECT * FROM users");

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

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