1.0.2 • Published 12 months ago

node-proxy-network-client v1.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 months ago

The node-proxy-network-client is a Node.js module designed to simplify making HTTP requests with proxy support using node-fetch. It is particularly useful for applications requiring to bypass network restrictions or mask IP addresses.

Install the module with npm:

npm i node-proxy-network-client

Configure your proxy by setting the HTTP_PROXY environment variable:

export HTTP_PROXY=http://your.proxy:8888

To make a request with custom options, utilize the fetch function. The API mirrors that of node-fetch:

const { fetch } = require('node-proxy-network-client');
const url = 'https://example.com/api/data';
const options = {};
fetch(url, options)
    .then(response => response.json())
    .then(data => {
        console.log(data);
    })
    .catch(error => {
        console.error('Error:', error);
    });

To make a GET request through a proxy, use the sendGetRequestAsync function:

const { proxyNetworkClient } = require('node-proxy-network-client');
const url = 'https://example.com/api/getData';
const options = {};
proxyNetworkClient.sendGetRequestAsync(url, options)
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.error('Error:', error);
    });
const { proxyNetworkClient } = require('node-proxy-network-client');
const url = 'https://example.com/api/postData';
const options = {
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        key: 'value'
    })
};
proxyNetworkClient.sendPostRequestAsync(url, options)
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.error('Error:', error);
    });

Integrate with other applications, such as using it as a network client for Azure MSAL Node:

const { ConfidentialClientApplication } = require('@azure/msal-node');
const { proxyNetworkClient } = require('node-proxy-network-client');
const client = new ConfidentialClientApplication({
    auth: {
        clientId,
        clientSecret
    },
    system: {
        networkClient: proxyNetworkClient
    }
});
1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago