# apolloagent

> Apollo 分布式配置中心 node 客户端

Latest version **1.0.1** (published 2018-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install apolloagent
pnpm add apolloagent
yarn add apolloagent
bun add apolloagent
```

Provides the command `apollo`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-03-13 |
| First published | 2018-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6.0 |
| Dependencies | 8 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | wangjianliang |
| Maintainers | lynn.wang |

## Links

- npm: https://www.npmjs.com/package/apolloagent
- Repository: git@newgit.op.ksyun.com:ksyun-fe/apolloagent
- npm.io page: https://npm.io/package/apolloagent

## Dependencies (8)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [assert](https://npm.io/package/assert.md) ^1.4.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [mustache](https://npm.io/package/mustache.md) ^2.3.0
- [commander](https://npm.io/package/commander.md) ^2.15.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^3.0.1

## Recent versions

- 1.0.1 (latest) — 2018-03-13

## README

# apolloagent

## Apollo 分布式配置中心 node 客户端

### support

```
nodejs cli
...
```

### install

```
npm install -S apolloagent
```

### run

```bash
#构建
npm run build
#发布
npm run release
```

### use

#### cli

```bash
apollo  -s http://*****:** -a {appid} -o "{output}" -w

###
apollo -h

  Usage: apollo [options]

  Options:

    -V, --version                output the version number
    -t, --template [template]    默认的配置模版 , 可以为空 (default: )
    -o, --output [output]        输出文件地址 (default: apollo-config.json)
    -a, --appId [appId]          请求的appId , 必填 (default: )
    -c, --cluster [cluster]      请求的集群 , 默认是 `default`  (default: default)
    -n, --namespace [namespace]  请求的命名空间 , 必填 (default: application)
    -w, --watch [watch]          是否开启监听改变 , 默认false (default: false)
    -s, --serve [serve]          请求服务地址 , 必填 (default: )
    -h, --help                   output usage information
###
```

### serve

```js
import apo from "apolloagent";
const agent = apo({
    appId: "{appid}",
    serve: "http:/****:**"
});
agent.requestFromCache(); //304缓存获取配置
agent.requestFromNoCache(); //非缓存获取配置
agent.shortPoll(); //轮询获取配置接口
agent.longPoll(); //挂起服务 ,实时响应配置更改
agent.on("change", function(data) {
    //监听数据源变化 , 执行shortPoll, longPoll有效
    console.log(data);
});
agent.writeConfigFile("", "./test/ss.json", true);
```

### API
- #apolloagent
    - params
        - appId = "",
        - serve = "",
        - namespace = "application",
        - cluster = "default",
        - options = {}
    - return
        - class
            - #requestFromCache
                - params
                - return
                    - promise
            - #requestFromNoCache
                - params
                - return
                    - promise
            - #shortPoll
                - params
                    - cb [function] 回调函数
                - return
                    - promise
            - #longPoll
                - params
                    - cb [function] 回调函数
                - return
                    - promise
            - #writeConfigFile
                - params
                    - template [string] 模版路径,可以为空,默认使用`mustache`渲染 , 空输出源数据
                    - output [string] 输出路径,必填,不能为空
                    - watch [boolean] 是否监控数据源改变
                - return 
                    - promise

### notes

>

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