如何使用REQUEST模块在nodejs中调用多个请求?

How to call multiple request in nodejs using REQUEST module?

我正在努力让它看起来更好, 我正在使用请求模块在同一台服务器上执行 http 请求,但使用不同的开发 ID 来检索设备值。

我有如下所示,但是有没有其他方法可以将它包含在一个调用中?

这是我的:

request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[1].ref2, (error, response, body) => {
            let object = JSON.parse(body);});

request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref1, (error, response, body2) => {
                let object2 = JSON.parse(body2);});

request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref3, (error, response, body3) => {
                let object3 = JSON.parse(body3);});

request("http://" + DEVLINK_IP.DEVLINK_IP + ":" + DEVLINK_port.DEVLINK_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref4, (error, response, body4) => {
                let object3 = JSON.parse(body4);});

这是我的一些脚本,我用它来:

// Issue the request
        request("http://" + DEV_IP.DEV_IP + ":" + DEV_port.DEV_port + "/JSON?request=getstatus&ref=" + addons.Lightning[1].ref2, (error, response, body) => {
            let object = JSON.parse(body);
        request("http://" + DEV_IP.DEV_IP + ":" + DEV_port.DEV_port + "/JSON?request=getstatus&ref=" + addons.Lightning[0].ref1, (error, response, body2) => {
                let object2 = JSON.parse(body2);
                // If there has been an error, log it
                if (error) console.error(error);
                
                
                

                message.channel.send({
                    embed: {
                        color: 3447003,
                        author: {
                            name: "Malosa-Lightning add-on",
                            icon_url: "https://icons.iconarchive.com/icons/jaan-jaak/weather/256/thunder-lightning-storm-icon.png"
                        },
                        title: "Lightning Detection",
                        url: "http://google.com",
                        description: "Current live info",
                        fields: [{
                            name: "Detection:",
                            value: (object.Devices[0].status)
                        },
                        {
                            name: "Masked links",
                            value: "You can put [masked links](http://google.com) inside of rich embeds."
                        },
                        {
                            name: "Markdown",
                            value: "You can put all the *usual* **__Markdown__** inside of them."
                        }
                        ],
                        timestamp: new Date(),
                        footer: {
                            icon_url: client.user.avatarURL,
                            text: "© Example"
                        }
                    }
                });
            });
        });

我找到了。

我改成了axios

使用时

const [response1, response2 ,response3] = await axios.all([
    axios.get("WEBSITE1"), 
    axios.get("WEBSITE2"), 
    axios.get("WEBSITE3"), 
]);

console.log (response1)
console.log (response2)
console.log (response3)