Include require.js to existing project

Hi!

I’m currently working on a modified version of balena-cam and therefore I want to include require.js to be able to use the require command in client.js file (e.g. to load ‘onoff’ for GPIO access).

What is the best way to do this? (changes in docker-compose.yml???)

Thank you for any help!

Hi,

I’m not entirely sure what you want o achieve with require.js and GPIO, could you elaborate on that?

If you make a local copy of the balena-cam repo on your computer you can modify the code and test directly on your local mode device using balena push <local addr>. Once you are happy with the changes, you can push to your fleet using balena push

Here is some information about local mode and balena push


Thx. But I’m already changing the code in local mode :wink: therefore I need the “onoff” module in client.js to manipulate GPIO pins, but unfortunately the require statement is not known:

ReferenceError: require is not defined

hence I need the require.js module.

Hi again, thanks for your reply, I understand now what you want to do.

The problem is that the require statement is a node.js keyword, but the code in client.js runs in your browser, where is not available. If you want to interact with the GPIO pins, you need to add that functionality on the server side of the application, and provide an interface to interact with it from the client code.

Here is some documentation on using GPIO on balena devices

Please let us know if that helps you