# bitspider-agent-baseservice

> [BitSpider Agent BaseService](https://munew.io) ===

Latest version **0.6.0** (published 2020-08-11) · 0 weekly downloads

## Install

```sh
npm install bitspider-agent-baseservice
pnpm add bitspider-agent-baseservice
yarn add bitspider-agent-baseservice
bun add bitspider-agent-baseservice
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2020-08-11 |
| First published | 2020-05-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 12 |
| Unpacked size | 4 MB |
| Known vulnerabilities | 0 (+38 in 6 direct dependencies) |
| Install scripts | no |
| Author | help.munewio@gmail.com |
| Maintainers | jackyma |

## Links

- npm: https://www.npmjs.com/package/bitspider-agent-baseservice
- npm.io page: https://npm.io/package/bitspider-agent-baseservice

## Dependencies (12)

- [ejs](https://npm.io/package/ejs.md) 3.1.3
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [uuid](https://npm.io/package/uuid.md) 8.3.0
- [axios](https://npm.io/package/axios.md) 0.19.2
- [lodash](https://npm.io/package/lodash.md) 4.17.19
- [morgan](https://npm.io/package/morgan.md) 1.10.0
- [express](https://npm.io/package/express.md) 4.17.1
- [winston](https://npm.io/package/winston.md) 3.3.3
- [fs-extra](https://npm.io/package/fs-extra.md) 9.0.1
- [serve-index](https://npm.io/package/serve-index.md) 1.9.1
- [cookie-parser](https://npm.io/package/cookie-parser.md) 1.4.5
- [server-destroy](https://npm.io/package/server-destroy.md) 1.0.1

## Recent versions

- 0.6.0 (latest) — 2020-08-11
- 0.5.1 — 2020-08-02
- 0.5.0 — 2020-06-29
- 0.4.3 — 2020-06-22
- 0.3.3 — 2020-06-11
- 0.3.2 — 2020-06-11
- 0.3.1 — 2020-06-10
- 0.3.0 — 2020-06-10
- 0.2.1 — 2020-05-25
- 0.2.0 — 2020-05-23
- 0.1.7 — 2020-05-21
- 0.1.6 — 2020-05-21
- 0.1.5 — 2020-05-21
- 0.1.4 — 2020-05-21
- 0.1.3 — 2020-05-21
- … 2 more at https://npm.io/package/bitspider-agent-baseservice/versions

## README

[BitSpider Agent BaseService](https://munew.io)
===

```js
const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen();
```

# Installation
This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/).

Before installing, [download and install Node.js](https://nodejs.org/en/download/).
> Node.js 12 or higher is required.

If this is a brand new project, make sure to create a `package.json` first with
the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file).

Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

```bash
$ npm install bitspider-agent-baseservice
```

[dia-agents-service](https://github.com/munew/dia-agents-service) is a good example

# Features
1. Implement RESTFul APIs to get and update intelligences to [Munew Engine](https://docs.munew.io/overview#munew-engine)
2. Default [Agent](https://docs.munew.io/overview#agent) is Service Agent

# APIs
## `express`
Create an [ExpressJS](https://expressjs.com/) app, and configure routes, JSON limit, static folder.

```js
const baseservice = require("bitspider-agent-baseservice");
baseservice.express();
```

#### Routes
1. `/`: return index page
2. `/health`: return health status of this server
3. `/agent`: return current agent configuration. If agent don't exist then return empty
4. `/log/combined.log`: All logs for debug purpose
5. `/log/error.log`: Error logs

#### JSON Limit
`100mb`

### Returns
- `Object`: [An Express Application Instance](https://expressjs.com/en/4x/api.html#express). You can use express API to add additional configuration

## `type`
Get or set agent type. Currently support type is `['BROWSEREXTENSION', 'HEADLESSBROSWER', 'SERVICE']`. Default is `SERVICE` type

```js
const baseservice = require("bitspider-agent-baseservice");
baseservice.express();
baseservice.type("HEADLESSBROWSER");
```

### Parameters
- `type:String`
  - Optional

### Returns
- `String|Object`: Type string or BaseService

## `worker`
Get or set worker. Worker responses for collect intelligences. Default it uses `service` worker.

```js
const { headlessWorker } = require("./workers/headlessWorker");
const baseservice = require("bitspider-agent-baseservice");
baseservice.express();
baseservice.type("HEADLESSBROWSER");
baseservice.worker(headlessWorker);
```

### Parameters
- `worker: Object`: worker object
  - Optional

### Returns
- `Object`: Woker object or BaseService

## `getPublic`
Return absolute path to `public` folder, anything you store in `public` folder, you can access by `/<path_to_file>`.

### Returns
- `String`: Absolute path to `public` folder

## `listen`
Start server, similar with `express.listen`

```js
const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen();
```
or
```js
const baseservice = require('bitspider-agent-baseservice');
baseservice.express();
baseservice.listen(9090);
```

### Parameters
- `port: Number`: Default will get from `process.env.PORT`, otherwise `8090`
  - Optional

### Returns
- `Promise`: Start successful, then `resolve(true)`, otherwise `reject(err)`

## `logger`
Return [winston](https://github.com/winstonjs/winston) logger, you can use this to add your logs, and view by `/log/combined.log` or `/log/error.log`

```js
const baseservice = require('bitspider-agent-baseservice');
const logger = baseservice.logger;
logger.info('Just for test');
```

### Returns
- `Object`: `winston` logger instance

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