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

**URL:** <https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621>\
**Category:** General\
**Created:** [25 March 2020 13:40 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621 "2020-03-25T13:40:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomtom30/32/2527_2.png) [@tomtom30](https://discourse.nodered.org/u/tomtom30)\
**Post date:** [25 March 2020 13:40 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/1 "2020-03-25T13:40:41Z")

</div>

Hi, I need your help about external module  
I try to use [faux-api-client](https://www.npmjs.com/package/faux-api-client) and I added it in settings.js and restart.

Here is my function code :

```auto
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

```auto

{ 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 :

```auto
    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

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [25 March 2020 13:47 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/2 "2020-03-25T13:47:42Z")

</div>

try:

```auto
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

---

<div class="post-metadata">

**Author:** ![tomtom30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomtom30/32/2527_2.png) [@tomtom30](https://discourse.nodered.org/u/tomtom30)\
**Post date:** [25 March 2020 14:27 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/3 "2020-03-25T14:27:18Z")

</div>

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

```auto

{
  "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

```

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [25 March 2020 14:44 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/4 "2020-03-25T14:44:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tomtom30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomtom30/32/2527_2.png) [@tomtom30](https://discourse.nodered.org/u/tomtom30)\
**Post date:** [25 March 2020 15:24 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/5 "2020-03-25T15:24:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tomtom30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomtom30/32/2527_2.png) [@tomtom30](https://discourse.nodered.org/u/tomtom30)\
**Post date:** [25 March 2020 19:06 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/6 "2020-03-25T19:06:45Z")

</div>

As I can see It need

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

```

instead of require, does it can make any difference?

---

<div class="post-metadata">

**Author:** ![tomtom30](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tomtom30/32/2527_2.png) [@tomtom30](https://discourse.nodered.org/u/tomtom30)\
**Post date:** [25 March 2020 23:37 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/7 "2020-03-25T23:37:12Z")

</div>

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

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

```

Thanks for your help

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 April 2020 23:37 UTC](https://discourse.nodered.org/t/solved-add-module-need-help-with-adding-external-npm-module/23621/8 "2020-04-08T23:37:13Z")

</div>

Closed on 8 April 2020 23:37 UTC

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