# Модуль http

http - устроен Node.js модуль, используемый для создания http сервера и отправки http запросов.

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

```
const http = require('http');

// Функция createServer создает сервер и получает коллбек.
// Коллбек отрабатывает каждый раз, как клиент запрашивает сервер
const server = http.createServer((req, res) => {
    // Коллбек принимает два параметра req (Request) и res (Response)
    // req содержит всю информацию о запросе клиента
    // res содержит всю информацию об ответе, что мы должны отправить клиенту
    // и вспомогательные методы для построения этого ответа
    // Объекты req i res являются уникальными для каждого запроса клиента
    
    console.log('Request received');
        
    res.statusCode = 200;
    res.end('My first server');
});

// Метод listen запускает наш сервер и указывает, на порте с каким номером
// необходимо принимать подключения от клиентов
// также он может принимать коллбек, что отработает после запуска сервера
server.listen(3000, () => {
    console.log ('Server started listening on port 3000');
});
```


---

# 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://reloaderlev.gitbook.io/russian-goit-node-js-new-program/veb-server-vstuplenie-v-express.js/modul-http.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.
