# Nodejs Modules

**URL:** <https://community.homey.app/t/nodejs-modules/77377>\
**Category:** Developers\
**Created:** [March 8, 2023, 10:42pm UTC](https://community.homey.app/t/nodejs-modules/77377 "2023-03-08T22:42:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rens\_Brandwijk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rens_brandwijk/32/12640_2.png) [@Rens\_Brandwijk](https://community.homey.app/u/Rens_Brandwijk)\
**Post date:** [March 8, 2023, 10:42pm UTC](https://community.homey.app/t/nodejs-modules/77377/1 "2023-03-08T22:42:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spkesDE](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/spkesde/32/54352_2.png) [@spkesDE](https://community.homey.app/u/spkesDE)\
**Post date:** [March 8, 2023, 11:01pm UTC](https://community.homey.app/t/nodejs-modules/77377/2 "2023-03-08T23:01:42Z")

</div>

You should use the package.json to manage modules

[example here](https://github.com/spkesDE/com.spkes.telegramNotifications/blob/master/package.json)

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…](https://heynode.com/tutorial/create-packagejson-file/)

## How to install a package

`npm install <packageName>`

[more here…](https://docs.npmjs.com/cli/v6/commands/npm-install)

## How to find packages

Take a look at [npmjs.com](http://npmjs.com)

---

<div class="post-metadata">

**Author:** ![Rens\_Brandwijk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rens_brandwijk/32/12640_2.png) [@Rens\_Brandwijk](https://community.homey.app/u/Rens_Brandwijk)\
**Post date:** [March 8, 2023, 11:07pm UTC](https://community.homey.app/t/nodejs-modules/77377/3 "2023-03-08T23:07:25Z")

</div>

Thanks!

Ik wil take a look at this later this week. This helps a lot.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 9, 2023, 6:28am UTC](https://community.homey.app/t/nodejs-modules/77377/4 "2023-03-09T06:28:02Z")

</div>

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')` ✅
