I have ‘build’ some apps for homey that lean on generic nodejs modules.
Its worth mentioning i’m not a native nodejs / js developer so i’m a bit lost in the folder structures at times.
Until now i have always managed to get my apps to work by adding a node_modules or modules folder in the root of the app and make a require function in my driver.js or app.js that Linked to the modules index file. This works fine for the old homey 2019.
As far as i can see there is nothing in the documentation about using modules in apps and drivers. And with the new hp23 this does not seem to work anymore.
Is there anyone who can explain how this should be done or if its blocked by athom. Thanks in advance.
You should use the package.json to manage modules
example here
If its not a NPM Module that you can ether create a local package npm install --save ../path/to/mymodule
or copy the required package to your file structure e.g. ./lib/myModule/
How to initiate a package json
- Enter the root folder of your project
- Run
npm init
- Fill out the prompts to create your package. json
more here…
How to install a package
npm install <packageName>
more here…
How to find packages
Take a look at npmjs.com
Thanks!
Ik wil take a look at this later this week. This helps a lot.
Also make sure that you either don’t use a directory prefix at all (for packages that are installed in node_modules
) or use a relative path (for packages that are in, for instance, a lib/
directory in your app). Never an absolute path.
In other words:
-
require('/node_modules/node-fetch')
-
require('node-fetch')
And:
-
require('/lib/MyModule')
-
require('./lib/MyModule')
2 Likes