Importing Package

image
When i tried to run this code in function node i get an error as ""ReferenceError: require is not defined ", please guide us How to use 'Request' Package in Node-red environment?

See the Node Configuration part of the docs https://nodered.org/docs/configuration

You can "require" it within the Node-RED settings file and then "get" it from the function node

But seeing as the code you are sharing looks like an http request - why not use the built in http-request node ?

Problem is i'm getting SSL3 handshake error while performing HTTP request. Hence using function node

Can you please be more precise? if you don't mind

More precise than to read a specific part of the relevant page in the docs? Which bit don’t you understand?

This is the section of the docs that explain how to load extra modules in the node: https://nodered.org/docs/writing-functions#loading-additional-modules

Upon reading the documentation it is suppose to get implemented in Terminal but how shall i do this
"cd ~/.node-red
npm install name_of_3rd_party_module" in cloud environment?

Which cloud environment?

from node-red in bluemix!

Hi @Trainocate

You'll need to edit your application's package.json file and add any additional modules you want into its package.json's dependencies section.

In order to edit the file, you must enable the Continuous Delivery integration option via your application’s IBM Cloud dashboard page. That will create a git repository on either GitHub or IBM DevOps services, from where you can edit the file, save the changes and push back into the cloud.

Nick

1 Like

Followed your instructions, in order to prevent the error "Require is not defined" which module am I suppose to add and how additional modules can be added in dependencies section
image

@Trainocate As the docs explain here: https://nodered.org/docs/writing-functions#loading-additional-modules you don't use require in your function node.

Your code uses the request module - I assume you'd want to add that to the dependencies section. Once you've done that, you can edit bluemix-settings.js and add an entry in functionGlobalContext for the module - just as the documentation describes.

Yes 'Request' module is the one which I will have to use in my code, but referring the link "https://nodered.org/docs/writing-functions#loading-additional-modules" it says that i should add modules in settings.js file. Kindly guide us how to add it exactly inside the dependencies section.

The example you linked to shows how to use the os module. Just replace os with whichever module you want to use.

@colin - os is built into node.js... external packages will also need to be added to your packages.json file - something like "request": "^2.88.1", in the dependencies section. You many not need the trailing comma t the end if it is the last one in the list.

Followed the instructions and deployed the project into IBM cloud but getting this message!