flowcomponents icon indicating copy to clipboard operation
flowcomponents copied to clipboard

How to include a require module in custom component

Open jayakumarj85 opened this issue 7 years ago • 6 comments

Hi,

I am trying to create a custom component for reading data from Azure Eventhubs. This requires the library require("@azure/event-processor-host") to be available in totaljs. Could you please let me know how can I add this library to totaljs so that my custom component gets installed successfully.

Thanks

jayakumarj85 avatar Dec 05 '18 17:12 jayakumarj85

In the component file add below line

exports.npm = ['@azure/event-processor-host'];

It will be installed automatically by Flow when the component is loaded. It might take some time to install so if you try to use it before that you may see an error in terminal. Just give it some more time.

molda avatar Dec 05 '18 18:12 molda

Thank you. I will try this out.

jayakumarj85 avatar Dec 05 '18 19:12 jayakumarj85

If I would like to call back the npm function (e.g. var test = require('tape') from https://www.npmjs.com/package/tape) directly in Flow Function without creating a component (exports.npm = ['tape']). May I know if there is a way to set this config? Thank you!

ductran54 avatar Nov 06 '19 18:11 ductran54

Hi, if have access to command line on the machine running the Flow then just run npm install tape in the app directory. Then you can use it.

molda avatar Nov 06 '19 18:11 molda

Yes, it is installed in the app/node_modules folder, but I couldn't call that function in Flow. When I used var test = require('tape'), it errors out that require is not a function. I also tried to set it as a global variable Tape : require('tape'), then using var tape = FLOW.variables.tape, but still not work

ductran54 avatar Nov 06 '19 19:11 ductran54

The componenet Function does not support require but Code should work

molda avatar Nov 06 '19 21:11 molda