Search code examples
node.jsnpmnode-modulespnpm

How share node_modules across two node projects with PNPM?


i have a project with two nodeJS projects inside, a backend project with inside a folder "client" for the frontend. Now i would like to make one common node_moduels folder both.

I found that PNPM could do that, but for me the documentation is not so clear. How doest it work? How can i run pnpm i on my root folder and then make my node_modules accessable for my "client" folder?

Thank you!


Solution

  • On Linux or Mac, i usually symlink the module (ln -s) into my other projects' libs. Then i import or require the module from there. It's located directly in your codebase, not in node_modules, but it works just fine.

    Just don't update the common module without keeping in mind all the dependant projects.

    For easy versioning, you may choose to publish your module to npm (even as private), and update it with each push for each of the dependants.