node-proxy-network-client
v1.0.2
Published
Network client for support proxy
Downloads
11
Maintainers
Readme
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
}
});