# Connect to Managed ClickHouse® with Node.js


Learn how to connect to your Managed ClickHouse® service with Node.js
using the official Node.js client for connecting to ClickHouse and the
HTTPS port.

## Prerequisites

-   [Node.js](https://nodejs.org/en/download/) in your environment
-   [Node.js client for connecting to
    ClickHouse](https://clickhouse.com/docs/integrations/language-clients/js/index#environment-requirements-nodejs)

> [!TIP]
> You can install the Node.js client for connecting to ClickHouse using
>
> ```bash
> npm i @clickhouse/client
> ```

## Identify connection information

To run the code for connecting to your service, first identify values of
the following variables:

|       Variable        | Description |
|-----------------------|-------------|
| `CLICKHOUSE_URL`      | `https://HOST:HTTPS_PORT`, where `HOST` and `HTTPS_PORT` are the host and port of the `clickhouse_https` component of your service, not the native port shown in the service URI |
| `CLICKHOUSE_USER`     | `User` for the ClickHouse connection |
| `CLICKHOUSE_PASSWORD` | `Password` for the ClickHouse connection |

## Connect to the service

Replace the placeholders in the code with meaningful information on your
service connection and run the code.

```javascript
import { createClient } from "@clickhouse/client"

const client = createClient({
    url: "CLICKHOUSE_URL",
    username: "CLICKHOUSE_USER",
    password: "CLICKHOUSE_PASSWORD",
    database: "default",
})
const response = await client.query({
    query : "SELECT 1",
    format: "JSONEachRow",
    clickhouse_settings: {
        wait_end_of_query: 1,
    },
})
const data = await response.json()
console.log(data)
```

> [!NOTE]
> Save the file with the `.mjs` extension, or set `"type": "module"` in your `package.json`,
> so that the `import` statement and the top-level `await` are accepted.

Now you have your service connection set up and you can proceed to
[uploading data into your database](/product/dbaas/service-specific/clickhouse/quick-start/#load-a-dataset).

For information on how to connect to the Managed ClickHouse service
with the ClickHouse client, see
[Connect with the ClickHouse client](/product/dbaas/service-specific/clickhouse/how-to/connect-with-clickhouse-cli/).

