Importing Package

#1

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?

0 Likes

#2

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

0 Likes

#3

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

0 Likes

#4

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

0 Likes

#5

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

0 Likes

#6

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

0 Likes

#7

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

0 Likes

#8

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?

0 Likes

#9

Which cloud environment?

0 Likes

#10

from node-red in bluemix!

0 Likes

#11

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

#12

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

0 Likes

#13

@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.

0 Likes

#14

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.

0 Likes

#15

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

0 Likes

#16

@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.

0 Likes

#17

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

0 Likes