---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.5
alternate:
  - https://yandex.com/dev/market/partner-api/doc/en/push-notifications/concepts/quick-start-notifications-node-express.md
  - https://yandex.com/dev/market/partner-api/doc/ru/push-notifications/concepts/quick-start-notifications-node-express.md
  - https://yandex.com/dev/market/partner-api/doc/zh/push-notifications/concepts/quick-start-notifications-node-express.md
  - href: zh/push-notifications/concepts/quick-start-notifications-node-express.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/market/partner-api/doc/zh/llms.txt

# 在节点上启动集成。js快递

本指南将帮助您从头开始在JavaScript中设置最简单的测试集成，以处理通知。 您可以检查您的服务器是否正在处理通知。

{% note info "您将需要一个节点。js和Java至少是版本11，以及用于检查服务器操作的Curl" %}

提前设置它们。 如何安装:

* [节点。js的](https://nodejs.org/en)

* [Java语言](https://www.java.com/ru/download/help/download_options.html)

* [卷曲,卷曲](https://curl.se/download.html)

{% endnote %}

## 下载 OpenAPI-规格 {#download}

{% list tabs %}

- 通过git

  1. 打开要保存规范的文件夹。 在本说明书中，将其称为 `<project_directory>`.
  1. 在其中运行命令提示符。
  1. 编写命令:

        ```no-highlight translate=no
        git clone https://github.com/yandex-market/yandex-market-notification-api.git
        ```

- 只是一个浏览器

  1. 下载 [Yandex的规格。市场通知服务 GitHub](https://github.com/yandex-market/yandex-market-notification-api/archive/refs/heads/main.zip).
  1. 将存档解压缩到要保存规范的文件夹。 在本说明书中，将其称为 `<project_directory>`.

{% endlist %}

## 生成服务器 {#generate}

1. 打开文件夹 `yandex-market-notification-api`，这出现在上一步。
1. 在其中运行命令提示符。
1. 编写命令:

    ```text translate=no
    npx @openapitools/openapi-generator-cli generate -i <path_to_openapi.yaml> -g nodejs-express-server -o <output_path>
    ```

作为一个 **输出路径** 指定项目所在的文件夹。

如果 **openapi工具**尚未安装，请接受安装。 在文件夹中 **输出路径** 客户端的文件将出现。

> **例子：**
>
> 假设您下载了一个存档并解压缩。 规范在文件夹中 `<project_directory>/yandex-market-notification-api`.
>
> 要将项目放在文件夹中吗 `<project_directory>/market-integration`.
>
> &#49;. 打开文件夹 `<project_directory>/yandex-market-notification-api`.
>
> &#50;. 在其中运行命令提示符。
>
> &#51;. 在打开的控制台中，写:
>
>        ```
>        npx@openapitools/openapi-generator-cligenerate-iopenapi/openapi.yaml-g javascript-o：no-translate[。./市场整合]
>        ```
>
> &#52;. 如果系统提示您安装生成器，请输入 **Y** 并点击 **进入**.

## 实施通知处理 {#code}

1. 在IDE中使用生成的代码打开该目录。
1. 在 `service/NotificationService.js` 通知处理逻辑所在。 添加一个简单的代码来处理与类型的通知 `PING`:

    ```javascript translate=no
    const Service = require('./Service');
    const logger = require('../logger');

    const sendNotification = (sendNotificationRequest) => new Promise(
      async (resolve, reject) => {
        try {
          if (sendNotificationRequest.body.notificationType == 'PING') {
            logger.info("PING notification processed")
          }
          // Возвращаем обязательное тело ответа
          resolve(Service.successResponse({
            name: "shop",
            time: new Date().toISOString(),
            version: "1.0.0"
          }));
        } catch (e) {
          reject(Service.rejectResponse(
            e.message || 'Invalid input',
            e.status || 405,
          ));
        }
      },
    );

    module.exports = {
      sendNotification,
    };
    ```

1. 写入控制台 `node index.js`. 服务器将启动。
1. 在单独的终端窗口中，向服务器发出测试请求:

    ```text translate=no
    curl -X POST -L 'http://localhost:8080/notification' -H 'Content-Type: application/json' -d '{"notificationType": "PING", "time": "2025-01-01T00:00:00.000Z"}'
    ```

1. 在回应中你会看到 `{"name":"shop","time":"2025-02-28t12:32:01.918Z","version":"1.0.0"}`，并在服务器记录消息 `PING notification processed`.
