# Node.js

{% hint style="success" %}
In Node.js, you can integrate the SDK using `@hackler/javascript-sdk`.

If you are using `@hackler/hackle-sdk`, you need to migrate to `@hackler/javascript-sdk`.
{% endhint %}

## Add SDK Dependency

[![](https://img.shields.io/npm/v/%40hackler%2Fjavascript-sdk)](https://www.npmjs.com/package/@hackler/javascript-sdk)

{% tabs %}
{% tab title="npm" %}

```shell
npm install --save @hackler/javascript-sdk
```

{% endtab %}

{% tab title="yarn" %}

```shell
yarn add @hackler/javascript-sdk
```

{% endtab %}
{% endtabs %}

## SDK Initialization

`hackleClient` is the class that provides methods for using SDK features.

To use the SDK, you need to initialize `hackleClient`.

#### Instantiation

Instantiate `hackleClient` by passing the SDK Key.\
`hackleClient` periodically synchronizes with the Hackle server as a background task to obtain the necessary information.

* You can find the SDK Key in [SDK Integration Info](https://dashboard.hackle.io/config/sdk-setting) located inside the Hackle Service Dashboard.

```javascript
const Hackle = require("@hackler/javascript-sdk");

// YOUR_SERVER_SDK_KEY 자리에 SDK 키를 넣습니다.
const hackleClient = Hackle.createInstance("YOUR_SERVER_SDK_KEY");
```

#### Initialization Complete

When the SDK is initialized, it fetches the necessary information from the Hackle server.

Initialization is performed asynchronously and you can receive the initialization completion callback via `onReady`.

{% hint style="warning" %}
If a user request arrives before the SDK is ready, **data may be lost.**
{% endhint %}

```javascript
hackleClient.onReady(() => {
  // SDK ready to use
  http.createServer((req, res) => {

  }).listen(3000)
});
```

## Shutdown

You must call the `close()` method when the application shuts down. This releases resources in use and sends any remaining events.

{% hint style="danger" %}
If the application shuts down without calling `close()`, **events may be lost.**
{% endhint %}

```javascript
process.on('SIGINT', function() {
  // kill signal
  hackleClient.close();
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/nodejs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
