# Add built-in module

Node-RED have a global context that can be pre-populated with objects when Node-RED starts. This is defined in the main settings.js file under the functionGlobalContext property.

For example, the built-in os module can be made available to all functions:

functionGlobalContext: {
  osModule:require('os')
}

at which point, the module can be referenced within a function as global.get('osModule').

If any external module is "required", it must be installed manually in the user directory via npm.

cd ~/.node-red
npm i name_of_3rd_party_module_to_be_required

# Update settings.js in Comongate

  1. Open settings.js available in path ./comongate/usr/node-red/
  2. Search functionGlobalContext
  3. Add your module reference as below

Function Global Context

# Manual NPM installation in Comongate node-RED

  1. Connect to portainer https://comongate_address/portainer/
  2. Log in as admin user

Portainer Login

  1. Access to Containers

Portainer Home

  1. Click on shell >_ of the Node-RED container

Portainer Container List

  1. Connect in Node-RED shell with Connect button

Portainer Container Console Connect

  1. The shell is connected in the right place, just send the command npm i name_of_3rd_party_module_to_be_required

Portainer Container Console Home

  1. Click on Disconnect, go to containers details and restart Node-RED container

Portainer Container Details

  1. Node-RED is still ready for using your module

You can call your module inside Node-Red function with this syntax:

var os = global.get('osModule')