enigma.js can be installed on your project using npm. Prerequisites are a Node.js installation of a version higher than 4.0 and a Git bash if you're running the example on Windows:
npm i -S enigma.js ws
npm stands for node package manager and represents a command-line interface program to manage Node.js (JavaScript) libraries, effectively a package manager. It consists of a command-line client and an online database of public and commercial private packages, which you can easily install by running npm install (-i) commands.
Next, you can create an example file (test.js):
const enigma = require('enigma.js'); const WebSocket = require('ws'); const schema = require('enigma.js/schemas/12.20.0.json'); // create a new session: const session = enigma.create({ schema, url: 'ws://localhost:9076/app/engineData', createSocket: url => new WebSocket(url), }); // bind traffic events to log what is sent and received on the socket: session.on('traffic:sent', data => console.log('sent:', data)); session.on('traffic:received', data => console.log('received:', data)); // open the socket and eventually receive the QIX global API, and then close // the session: session.open() .then((/*global*/) => console.log('We are connected!')) .then(() => session.close()) .then(() => console.log('Session closed')) .catch(err => console.log('Something went wrong :(', err));
(This example is taken from enigma's official repository documentation, which can be found at https://github.com/qlik-oss/enigma.js/.)
The last thing you need to do is to run the Node.js command line:
node my-file.js
Using enigma.js for your project requires a good understanding of JavaScript, promises, and WebSockets. It is recommended that you read Chapter 12, Coding in Qlik Sense, if those keywords don't ring a bell.