# node-global-proxy

> A global proxy for Node.JS with friendly API

Latest version **1.0.1** (published 2020-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-global-proxy
pnpm add node-global-proxy
yarn add node-global-proxy
bun add node-global-proxy
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-06-03 |
| First published | 2020-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wwwzbwcom |
| Maintainers | wwwzbwcom |

## Links

- npm: https://www.npmjs.com/package/node-global-proxy
- npm.io page: https://npm.io/package/node-global-proxy

## Dependencies (2)

- [global-agent](https://npm.io/package/global-agent.md) ^2.1.12
- [global-tunnel-ng](https://npm.io/package/global-tunnel-ng.md) ^2.7.1

## Recent versions

- 1.0.1 (latest) — 2020-06-03
- 1.0.0 — 2020-06-03

## README

# Node Global Proxy

Global Proxy for Node.JS with Friendly APIs.

Work with Axios, Request, Got, Superagent etc.

## Install

```bash
npm install node-global-proxy --save
```

## Introduction

Basic use with Javascript:

```js
const proxy = require("node-global-proxy").default;

proxy.setConfig("localhost:1080");
proxy.start();

/** Proxy working now! */

proxy.stop();

/** Proxy stop working now! */
```

Also, you can use a config object

```js
const proxy = require("node-global-proxy").default;

proxy.setConfig({
  http: "http://localhost:1080",
  https: "https://localhost:1080",
});
proxy.start();

/** Proxy working now! */

proxy.stop();

/** Proxy stop working now! */
```

Use with typescript or es6+

```ts
import proxy from "node-global-rpoxy";

proxy.setConfig("http://localhost:1080");
proxy.start();
```

### API

- `proxy.start()` Start using global proxy
- `proxy.stop()` Stop using global proxy
- `proxy.setConfig(config : string | NodeGlobalProxyConfig)` Set config global proxy by url string or config object
- `proxy.getConfig()` Get current config object
- `proxy.system()` Get system config and set as node global proxy

### Examples

This is an example with a proxy server run on `localhost:10809`, and get ip information from system proxy, no proxy and user config proxy.

```js
const axios = require('axios');
const proxy = require('node-global-proxy').default;

let PROXY_URL = "localhost:10809"

const test = async () => {
    console.log(proxy);

    proxy.system();
    console.log(proxy.getConfig());
    res = await axios.get("http://ip-api.com/json", {
        timeout: 3000
    });
    console.log(res.data);

    proxy.setConfig(PROXY_URL);
    console.log(proxy.getConfig());

    proxy.start();
    res = await axios.get("http://ip-api.com/json", {
        timeout: 3000
    });
    console.log(res.data);

    proxy.stop();
    res = await axios.get("http://ip-api.com/json", {
        timeout: 3000
    });
    console.log(res.data);

    proxy.setConfig({
        http: "http://" + PROXY_URL,
        https: "https://" + PROXY_URL
    });
    console.log(proxy.getConfig());
    proxy.start();
    res = await axios.get("http://ip-api.com/json", {
        timeout: 3000
    });
    console.log(res.data);
}

test();
```

---
_Source: https://npm.io/package/node-global-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
