> For the complete documentation index, see [llms.txt](https://docs.pureservers.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pureservers.org/sdk/nodejs.md).

# NodeJS

Требуемые библиотеки:

| Библиотека | Версия |
| ---------- | ------ |
| axios      | ^1.6.5 |

Код SDK:

```javascript
const axios = require('axios');

class PureServers {
    constructor(email, password) {
        this.email = email;
        this.password = password;
        this.session = null;
    }

    async request(url, method, data = {}, secured = false) {
        try {
            const res = await axios({
                url: `https://cp.pureservers.org/api/${url}`,
                method,
                ...(method === 'POST' ? { data } : {}),
                ...(secured && this.session ? {
                    headers: {
                        session: this.session
                    }
                } : {})
            });

            return { data: res?.data, headers: res?.headers, success: true };
        } catch(err) {
            return { data: err?.response?.data, headers: err?.response?.headers, success: false };
        }
    }

    async login() {
        const res = await this.request('auth/login', 'POST', { email: this.email, password: this.password });
        if(res.success) {
            this.session = res.headers.session;
            return true;
        }

        return res;
    }
}
```

Пример использования с получением списка серверов:

```javascript
async function main() {
    const api = new PureServers('<email>', '<password>');
    const login = await api.login();
    if(login) console.log(await api.request('servers/list', 'GET', {}, true));
    else console.log('Failed to login', login);
}

main();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.pureservers.org/sdk/nodejs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
