# Adding node module to p5.js

**URL:** <https://discourse.processing.org/t/adding-node-module-to-p5-js/28842>\
**Category:** Libraries\
**Created:** [March 25, 2021, 6:21pm UTC](https://discourse.processing.org/t/adding-node-module-to-p5-js/28842 "2021-03-25T18:21:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cenkakay08](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@cenkakay08](https://discourse.processing.org/u/cenkakay08)\
**Post date:** [March 25, 2021, 6:21pm UTC](https://discourse.processing.org/t/adding-node-module-to-p5-js/28842/1 "2021-03-25T18:21:48Z")

</div>

Hi everyone. I’m working on bin packing project. I want to use node module to placement of rectangles.

Node module that I want to use: [rectangle-bin-pack - npm](https://www.npmjs.com/package/rectangle-bin-pack)

I’m using p5.vscode extension on VS code for develop. Is there any tutorial or document to about adding node modules? Thanks already for your help. Have a nice day.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 25, 2021, 7:26pm UTC](https://discourse.processing.org/t/adding-node-module-to-p5-js/28842/2 "2021-03-25T19:26:51Z")

</div>

Hi! welcome to the forum!

In short, it’s not possible in this case (or at least it’s not easy).

Long answer - unfortunately this package uses c++, so it only runs on node.js and not on client/browser - maybe you can use webassembly but you need to port the code and compile it by yourself, I guess. If the npm module is built only by javascript, it may be possible to run on the client side. Just like you include p5.js in an html file, you can include the module as standalone js file (for example, like adding ml5.js) which will be exposed as global variables. Another way, which is more “elegant”, is to use tools like browserify to bundle all the javascript file including modules (p5.js etc) into a single js file and include it in the html file. The advantage is that you can keep track of dependencies of npm modules by package.json (but again, this does not support every npm module, and the one you mentioned cannot be included because of the reason above), but the downside is that you need to set up your environment for development.

---

<div class="post-metadata">

**Author:** ![cenkakay08](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@cenkakay08](https://discourse.processing.org/u/cenkakay08)\
**Post date:** [March 25, 2021, 8:02pm UTC](https://discourse.processing.org/t/adding-node-module-to-p5-js/28842/3 "2021-03-25T20:02:35Z")

</div>

Thank you for answer, I think I should find another node module to packing. After that I will try to adding standalone or with Browserify.
