> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js

> This page outlines the steps to connect Node.js to the Connect AI Virtual SQL Server API.

## Prerequisites

Before you connect, you must first do the following:

* Connect a data source to your Connect AI account. See [Sources](/ja/Sources) for more information.
* Generate a Personal Access Token (PAT) on the [Settings](/ja/Settings#personal-access-tokens) page. Copy this down, as it acts as your password during authentication.

## Connect to Connect AI

In order to connect from Node.js to Connect AI via the SQL Server interface, you need the following information:

* **Server**—*tds.cdata.com*
* **Port**—*14333*
* **Database name**—接続したいConnect AI データソースのConnection Name を入力します。例：*Salesforce1*
* **Username**—Connect AI のユーザー名を入力します。ユーザー名は、Connect AI の画面の右上に表示されています。例：*[test@cdata.co.jp](mailto:test@cdata.co.jp)*
* **Password**—[Settings](/ja/Settings#personal-access-tokens) ページで生成したPAT を入力します。

Use the following code to connect to your database with Node.js, and change the following:

* Update `user` with your Connect AI username.
* Update `password` with the PAT you generated in the prerequisites.
* Update `database` with the name of the data source you created in the prerequisites.
* Replace the `query` with your database query.

```javascript expandable theme={null}
var sql = require('mssql')
var config = {
   server: 'tds.cdata.com',
   port: 14333,
   user: 'user@mydomain.com', //your Connect AI username
   password: 'CONNECT_USER_PAT', //your Connect AI PAT  
   options: {
      encrypt: true,
      database: 'SAPHANA1' //the name of your database connection
   }
}
 
sql.connect(config, err => {
   if(err){
      throw err ;
   }
   new sql.Request().query('SELECT * FROM Buckets', (err, result) => { //your query
      console.dir(result)
   })
 
});
 
sql.on('error', err => {
   console.log("SQL Error: " ,err);
})
```
