[ Solved ] [ Add module ] Need help with adding external npm module

Hi, I need your help about external module
I try to use faux-api-client and I added it in settings.js and restart.

Here is my function code :

var fauxapi = context.global.fauxapi;
console.log(fauxapi);
const client = new fauxapi ( 'https://192.168.1.1', 'PFFA6', 'qes1sgg81YuyC8s' );
msg.payload = client;
return msg;

I get this return in console


{ FauxApiClient: [Function: FauxApiClient] }


25 Mar 14:37:23 - [error] [function:6dd44643.560218] TypeError: fauxapi is not a constructor

I don't understand why.

Here is my settings.js :

    functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
        fcm:require('fcm-node'),
        fauxapi:require('faux-api-client')
    },

fcm-node works great.

Thank you for your help
Thomas

try:

var fauxapi = global.get("fauxapi");

and make sure you did the npm install faux-api-client from your nodered directory. Eg '~/.node-red' on a raspberry.
Best regards Johannes

Thanks.
Yes I tried it too. I get the same result.
I'am sure it correctly install , I see it in package.json.


{
  "name": "node-red-project",
  "description": "A Node-RED Project",
  "version": "0.0.1",
  "dependencies": {
    "faux-api-client": "^1.0.9",
    "fcm-node": "^1.5.2",
    "lgtv2": "^1.4.1",
    "node-red-configurable-ping": "^1.0.1",
    "node-red-contrib-advance-logger": "~1.0.1",
    "node-red-contrib-advanced-ping": "^1.2.0",
    "node-red-contrib-alexa-remote2": "~3.7.0",
    "node-red-contrib-alexa-smart-home": "~0.4.66",
    "node-red-contrib-asterisk": "0.0.3",
    "node-red-contrib-bigssh": "^1.2.4",
    "node-red-contrib-blindcontroller": "^4.8.5",
    "node-red-contrib-cast": "~0.2.12",
    "node-red-contrib-counter": "^0.1.5",
    "node-red-contrib-face-recognition": "~1.3.2",
    "node-red-contrib-firebase": "^1.1.1",
    "node-red-contrib-google-home-notifier-offline": "~0.1.0",
    "node-red-contrib-google-home-notify": "0.0.7",
    "node-red-contrib-harmony": "^1.2.6",
    "node-red-contrib-harmony-websocket": "~2.2.1",
    "node-red-contrib-kodi": "^0.2.8",
    "node-red-contrib-lgtv": "^1.1.0",
    "node-red-contrib-message-counter": "~1.0.1",
    "node-red-contrib-metrics": "0.0.1",
    "node-red-contrib-modbus": "^4.1.3",
    "node-red-contrib-mongodb2": "~0.5.6",
    "node-red-contrib-mongodb3": "~2.0.1",
    "node-red-contrib-openhab-v2": "~1.4.1",
    "node-red-contrib-squeezebox": "^0.1.1",
    "node-red-contrib-sunpos": "^1.4.1",
    "node-red-contrib-time-range-switch": "~0.6.3",
    "node-red-dashboard": "~2.19.0",
    "node-red-node-base64": "~0.2.0",
    "node-red-node-email": "~1.7.2",
    "node-red-node-msgpack": "~1.2.0",
    "node-red-node-mysql": "0.0.19",
    "node-red-node-openweathermap": "~0.2.1",
    "node-red-node-random": "~0.1.4",
    "node-red-node-serialport": "~0.9.2",
    "node-red-node-suncalc": "0.0.12",
    "node-red-node-tail": "0.0.3",
    "node-red-node-weather-underground": "^0.1.12",
    "node-red-node-wol": "~0.1.0",
    "serialport": "^7.1.5",
    "websocket": "^1.0.30"
  }
}

Thanks

hmm i have no experience with projects. But in a normal environment the above definitely works for me :thinking:

I Don't understand because I did the same with fcm-node and it works.
Can it due to this package in particulary?

As I can see It need

import {FauxApiClient, IFauxApiResponse} from 'faux-api-client';

instead of require, does it can make any difference?

Ok I have found my mistake.
In this case I need to call :

const fauxapi = global.get("fauxapi.FauxApiClient");

Thanks for your help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.