node-fetch-with-proxy
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "node-fetch-with-proxy", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "node-fetch with proxy-agent", | ||
@@ -5,0 +5,0 @@ "main": "lib/fetch-with-proxy.js", |
@@ -5,8 +5,6 @@ # node-fetch-with-proxy | ||
The proxy specified by the environment variable (HTTP_PROXY, https_proxy, etc.) is used in Node.js environment. | ||
## Install | ||
```sh | ||
$ npm install node-fetch-with-proxy | ||
npm install node-fetch-with-proxy | ||
``` | ||
@@ -16,15 +14,19 @@ | ||
See [node-fetch](https://www.npmjs.com/package/node-fetch) | ||
API is the same as `node-fetch`. | ||
## Advanced Usage | ||
```javascript | ||
const fetch = require('node-fetch-with-proxy'); | ||
You can explicitly specify proxy options with the 3rd argument of `fetch` API. | ||
fetch('http://httpbin.org/get') | ||
.then(res => res.json()) | ||
.then(json => console.log(json)); | ||
``` | ||
```javascript | ||
const proxyUrl = 'http://your.proxy:port'; | ||
Unlike node-fetch, proxy can be set by environment variable. | ||
fetch('https://httpbin.org/post', { | ||
method: 'POST', | ||
body: 'foo=bar' | ||
}, proxyUrl); | ||
```sh | ||
export HTTP_PROXY=http://your.proxy:8888 | ||
``` | ||
Environment variables are only valid for Node.js. | ||
Note that the browser uses its own proxy settings instead. |
31