npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

appcd-client

1.3.1 • Public • Published

appcd-client

The Node.js client for connecting to the Appc Daemon. Internally appcd-client uses a WebSocket for communicating with the server.

Visit https://github.com/appcelerator/appc-daemon for more information.

Installation

npm i appcd-client

Usage

import Client from 'appcd-client';
 
const client = new Client();
 
client
    .request('/appcd/status')
    .on('response', status => {
        console.log(status);
        client.disconnect();
    })
    .on('error', err => {
        console.error('ERROR!');
        console.error(err);
    });

To subscribe to a service:

client
    .request({
        path: '/appcd/status/system/loadavg',
        type: 'subscribe'
    })
    .on('response', status => {
        console.log(status);
        client.disconnect();
    })
    .on('error', err => {
        console.error('ERROR!');
        console.error(err);
    });

Starting the Appc Daemon

request() will automatically call connect(), however it will error if the daemon is not running. You can call connect() prior to making your request and specify the startDaemon flag:

const client = new Client();
 
(async () => {
    try {
        // connect to the daemon and start it if its not running.
        await new Promise((resolve, reject) => {
            client
                .connect({ startDaemon: true })
                .on('connected', resolve)
                .on('error', reject);
        });
 
        await new Promise((resolve, reject) => {
            client
                .request('/appcd/status')
                .on('response', status => {
                    console.log(status);
                    client.disconnect();
                    resolve();
                })
                .on('error', reject);
        });
    } catch (err) {
        console.error('ERROR!');
        console.error(err);
    }
})();

Legal

This project is open source under the Apache Public License v2 and is developed by Axway, Inc and the community. Please read the LICENSE file included in this distribution for more information.

install

npm i appcd-client

Downloadsweekly downloads

22

version

1.3.1

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability