# Connect to Turso using JavaScript

> Connect to Turso using JavaScript — Turso documentation.
> Canonical HTML: https://tursodb.cn/docs/connect/javascript/
> Upstream Source (MIT): https://docs.turso.tech/connect/javascript
> Language: en

---
## Quickstart

**1. Install**

Add the Turso database package to your JavaScript project:

```bash
npm i @tursodatabase/database
```

**2. Connect**

Here's how you can connect to a local SQLite database:

```javascript
import { connect } from "@tursodatabase/database";

const db = await connect("sqlite.db");
```

**3. Create table**

Create a table for users:

```javascript
const createTable = db.prepare(`
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL
  )
`);
createTable.run();
```

**4. Insert data**

Insert some data into the users table:

```javascript
const insertUser = db.prepare("INSERT INTO users (username) VALUES (?)");
insertUser.run("alice");
insertUser.run("bob");
```

**5. Query data**

Query all users from the table:

```javascript
const stmt = db.prepare("SELECT * FROM users");
const users = stmt.all();
console.log(users);
```

## Examples

Explore these JavaScript examples to learn more about using Turso Database:

* [Node](https://github.com/tursodatabase/turso/blob/main/examples/javascript/database-node) — Node.js, local file database (no sync)
* [Wasm + Vite](https://github.com/tursodatabase/turso/blob/main/examples/javascript/database-wasm-vite) — Browser (WASM), local database in the browser
