# shadowsocks-server-api

> Node.js library to communicate with the shadowsocks-restful-api

Latest version **1.1.3** (published 2019-10-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install shadowsocks-server-api
pnpm add shadowsocks-server-api
yarn add shadowsocks-server-api
bun add shadowsocks-server-api
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2019-10-19 |
| First published | 2019-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | ZZQ |
| Maintainers | mrzzq |

## Links

- npm: https://www.npmjs.com/package/shadowsocks-server-api
- Repository: https://github.com/DrZZQ/shadowsocks-server-api
- npm.io page: https://npm.io/package/shadowsocks-server-api

## Dependencies (1)

- [request](https://npm.io/package/request.md) ^2.88.0

## Recent versions

- 1.1.3 (latest) — 2019-10-19
- 1.1.2 — 2019-10-19
- 1.1.1 — 2019-10-19
- 1.1.0 — 2019-10-19

## README

# shadowsocks-server-api
Node.js library to communicate with the [shadowsocks-restful-api](https://github.com/shadowsocks/shadowsocks-restful-api)

## Installation
```shell
npm i shadowsocks-server-api
```

## Usage
To start a new instance:
```js
const SsApi = require('shadowsocks-server-api')

const ssApi = new SsApi()

let server = {
  host: 'Your server host',
  port: 4001, //Port of shadowsocks-restful-api
  token: '',
  password: 'pleaseChangeThisPassword'
}
```
<!--
### Running the integration tests
Edit
```js
{
  host: 'localhost',
  port: 4001,
  token: '',
  password: 'pleaseChangeThisPassword'
}
```
```shell
npm test
```
-->
### Login
###### ssApi.login()
```js
ssApi.login(server, (error, response, token) => {
    // Returns response Object and an error if it contains one
    console.log(token) //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NzE0NzIx...
  }
})
```

### Ping
###### ssApi.getPing()
```js
ssApi.getPing(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // {"pong":"pong"}
  }
})
```

### Add port
###### ssApi.addPort()
```js
let portConfig = { // Config for shadowsocks port
  port: 'port_number',
  password: 'port_password',
  method: 'encryption_method'
}

ssApi.addPort(server, portConfig, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(response.statusCode) // 201 Created
  }
})
```

### Get all ports
###### ssApi.getPorts()
```js
ssApi.getPorts(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // [{"port":port_number, "password":"port_password","method":"encryption_method"}, ... ]
  }
})
```

### Delete a port
###### ssApi.deletePort()
```js
let port_to_delete = 4242

ssApi.deletePort(server, port_to_delete, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(response.statusCode) // 204 No Content
  }
})
```

### Get traffic for all ports
###### ssApi.getTrafic()
```js
ssApi.getTrafic(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // [{"port":port_number, "traffic": traffic_usage}, ... ]
  }
})
```

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