Skip to main content

Setup node.js microservices

Microservices are mostly pretty straight forward. Web apis that expose some kind of data to the UI.

Node.js service have a 75% unit test coverage threshold

NodeMSP is built on the hapi framework

Setup dwp-middleware

In order to sucsessfully run npm install, you will need some prerequirements. For instance node-gyp, Python3 and Java-SDK. Keep in mind the node version of the MSP, this can be found in package.json. As of 19.09.2024 this is v20 for dwp-middleware.

Install node-gyp:

npm install node-gyp

Install Windows build tools

choco install python visualstudio2022-workload-vctools -y

Make sure the versions are correct, Python >= v3.12 requires node-gyp >= v10.

Downloading Java-DK

Now, find the correct version of Java-DK in the Dockerfile in dwp-middleware. It should be stated like:

RUN microdnf install -y java-VERSION_NUMBER-openjdk-devel

Find the latest available release of Java-DK matching the stated VERSION_NUMBER here.

Download the zip file, unzip it in D:\ or anywhere making sense.

You need to set the JAVA_HOME environment variable and add the unzipped Java-DK bin directory to your PATH:

  • Right-click on This PC, and choose Properties > Advanced system settings > Environment Variables
  • Under System variables, click New
  • Add Variable name: JAVA_HOME and Variable value: D:\path\to\jdk
  • Find the Path variable in the System variables section, select it, and click Edit.
  • Add a new entry for D:\path\to\jdk\bin

Restart the terminal and you should now be able to npm install without problems!

If you have time: Make the below fix as a Merge Request to dwp-middleware so we don't need to do it manually every time

Get the config file

Get the response of the following request and save it in the root of the dwp-middleware repo as local-dsisconfig.json alt text

Prepare the iwp.js file

const fs = require('fs').promises;
const path = require('path');

// Function to load configuration
async function loadDwpConfig(response) {
// Define the path to the local config file
const localConfigPath = path.join(__dirname, 'local-dsisconfig.json');

try {
// Check if local config file exists and use it if found
await fs.access(localConfigPath);
const localConfig = await fs.readFile(localConfigPath, 'utf8');
logger.info('Using local dsisconfig.json');
return JSON.parse(localConfig); // Use local config
} catch (err) {
// If local file doesn't exist or there's an error, fall back to the remote response
logger.info('Local dsisconfig.json not found, using remote response');
return response; // Fallback to the response
}
}

In dwp-middleware -> iwp.js

  1. Paste the above function loadDwpConfig somewhere smart
  2. Find+Replace the following
dwpConfig = response;

with

const dwpConfig = await loadDwpConfig(response);

Run the microservice again

Setup microservice-akerbp-kick-tolerance

  1. Clone the repo
git clone https://gitlab.com/ds365ai/snowleopard/AkerBP/microservice-akerbp-kick-tolerance
  1. Rename \src\plugins\routes\kick-tolerance.ts to \src\plugins\routes\kick-tolerance.js

    1. This workaround is in place because of a dependency typo that will not get fixed in /node_modules/nodemsp/core/kafka/consumer.js:26
  2. fnm use 18

  3. npm install

  4. npm run dev

  5. Use attach by port from vscode to debug/set breakpoints

Misc.

DWP Customizations, what is possible in DWP

Connecting...