# awv3-node

> node.js classcad instance manager

Latest version **10.0.3** (published 2021-01-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install awv3-node
pnpm add awv3-node
yarn add awv3-node
bun add awv3-node
```

## 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 | 10.0.3 |
| Published | 2021-01-13 |
| First published | 2016-06-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 28 |
| Unpacked size | 337.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Paul Henschel |
| Maintainers | drcmda, dm385 |

## Links

- npm: https://www.npmjs.com/package/awv3-node
- Repository: https://github.com/awv3-informatik/awv3-node
- Homepage: https://github.com/awv3-informatik/awv3-node#readme
- Issues: https://github.com/awv3-informatik/awv3-node/issues
- npm.io page: https://npm.io/package/awv3-node

## Dependencies (28)

- [ws](https://npm.io/package/ws.md) ^6.0.0
- [ora](https://npm.io/package/ora.md) ^3.0.0
- [cors](https://npm.io/package/cors.md) ^2.8.4
- [guid](https://npm.io/package/guid.md) ^0.0.12
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [delay](https://npm.io/package/delay.md) ^3.1.0
- [redux](https://npm.io/package/redux.md) ^4.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [moment](https://npm.io/package/moment.md) ^2.22.2
- [emitter](https://npm.io/package/emitter.md) ^0.0.5
- [express](https://npm.io/package/express.md) ^4.16.3
- [threads](https://npm.io/package/threads.md) ^0.12.0
- [fix-path](https://npm.io/package/fix-path.md) ^2.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.0
- [os-utils](https://npm.io/package/os-utils.md) ^0.0.14
- [socket.io](https://npm.io/package/socket.io.md) ^2.1.1
- [stoppable](https://npm.io/package/stoppable.md) ^1.0.6
- [bufferutil](https://npm.io/package/bufferutil.md) 4.x.x
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.2.0
- [portfinder](https://npm.io/package/portfinder.md) ^1.0.17
- [compression](https://npm.io/package/compression.md) ^1.7.3
- [redux-thunk](https://npm.io/package/redux-thunk.md) ^2.3.0
- [serve-index](https://npm.io/package/serve-index.md) ^1.9.1
- [redux-logger](https://npm.io/package/redux-logger.md) ^3.0.6
- [utf-8-validate](https://npm.io/package/utf-8-validate.md) 5.x.x
- [connect-timeout](https://npm.io/package/connect-timeout.md) ^1.9.0
- [is-port-available](https://npm.io/package/is-port-available.md) ^0.1.5
- [stringify-object-extract-functions](https://npm.io/package/stringify-object-extract-functions.md) ^2.4.1

## Recent versions

- 10.0.3 (latest) — 2021-01-13
- 9.0.1 (beta) — 2018-08-17
- 10.0.3-beta.1 — 2021-01-12
- 10.0.2 — 2020-10-30
- 10.0.1 — 2020-08-19
- 10.0.0 — 2020-08-05
- 9.0.6 — 2020-06-25
- 9.0.5 — 2020-05-19
- 9.0.4 — 2020-02-18
- 9.0.3 — 2019-01-15
- 9.0.2 — 2018-08-30
- 9.0.0 — 2018-08-17
- 8.2.33 — 2018-08-14
- 8.2.32 — 2018-08-13
- 8.2.31 — 2018-04-25
- … 130 more at https://npm.io/package/awv3-node/versions

## README

# ClassCAD instance manager based on Node.js

This is a Node.js implementation using Socket.IO as the communications protocol.

![](intro.jpg)

# Install

    npm install awv3-node

# Instance server

The instance manager represents a single endpoint where users connect in order to work with ClassCAD sessions.
It may ship ClassCAD binaries and boot them up when starting, but it can also rely on seperate 'farms', servers that host ClassCAD processes.

```js
const path = require('path')
const Server = require('awv3-node/server').default
const Logger = require('awv3-node/extras/logger').default

const server = new Server(
  {
    instances: 1,
    // The following are all defaults ...
    executable: 'ClassCADInstance.exe',
    configurationData: 'CADApplication.ini',
    output: path.resolve('./node_modules/@awv/classcad_cadapplication'),
    protocol: 'http',
    serverOptions: {},
    ip: 'localhost',
    privatePort: 0,
    publicPort: 8181,
    binary: true,
    multipart: true,
    compression: true,
    sendTreePatches: true,
    stdout: false,
    secureApi: false,
    debug: true,
    showConsole: false,
    stateDebounce: 500,
    workerTimeout: 1000 * 15,
    restTimeout: 1000 * 60 * 2,
    collectResultsOnly: true,
    logExpirationDays: 5,
  },
  Logger({ spinOnFirstUser: true }),
).start()
```

# REST API

Log in a new user with the /login endpoint. The user will be treated in the same way as a socket.IO user.
This has been abstracted in the awv3 library under the /communication/rest class which features the same API
as the socketio or the signalr classes.

    GET /login/:id

        response => { op: 'system', status: [either 'permitted' or 'rejected'], id: [session ID] }

Log out with the /logout endpoint

    GET /logout/:id

        response => "disconnected"

Execute tasks with the /execute endpoint. Note that due to the limitations of REST, there is no server push available.
Results will be sent in a single, complete chunk. Another limitation is that requests may time out, should the server be too busy.
Such errors need to be handled by the client.

    POST /execute/:id
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        method: "POST",
        body: JSON.stringify(command)

        response => Array of results

# Custom load balancing

Override the [server.health] function to determine the instances health status. The function must return a HTTP status code.
Load balancers can probe the /health endpoint to flag single instances as busy, which will remove them from the set of balanced instances until they become active again. The default criteria seeks to flag an instance as not-healthy (status code 503, service unavailable) if 90% of its ClassCAD sessions are busy.

```js
server.health = function() {
  let sessions = Array.from(server.sessions.values())
  let busy = 0
  for (let session of sessions) if (session.tasks.size > 0) busy++

  // If 90% are busy, start flagging the instance as unhealthy
  return busy > sessions.length * 0.9 ? 503 : 200
}
```

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