Node modules

I got some free time and decided to see what a nodejs project is and how hard/easy it is to work with it compared to PHP. The following question immediately arose:

When I deploy a project through Docker, the size of the project folder on the computer is adequate (about 6 megabytes for a simple Hello World). If when creating a project I choose custom hosting or hosting on Heroku, then it will be necessary to install indecently many nodejs modules. Because of this, the project folder on your computer will take up 163 megabytes for a simple Hello World, the total number of installed modules will be 508…

Q: is this normal for nodejs projects? If so, do I understand correctly that these modules are necessary for the normal operation of the node server, and in the case of Docker, all the necessary environment is located in the container itself and therefore there is no need to install all these modules, and therefore the project folder takes up only 6 megabytes?

1 Like

hello @Mr.Rubi,
Some node modules are used within the components provided by wappler and some modules are waiting for future components. (example: socket.io) … so this is normal.

1 Like

The files in node_modules are required while developing the project. The folder will not be uploaded to a production version.

2 Likes

Thank you @ben and @s.alpaslan for the answers.

I thought so, but I wanted to clarify. It looks like we'll have to put up with it, although I think it's extremely wasteful. While I was checking various settings, I created 10 Hello World projects (sites with one line of text) that take up more than 1.6 gigabytes on the computer... It seems that just recently 50 megabytes was considered an incredibly large HDD :slightly_smiling_face: We all become wasteful...

Yes, the entire node_modules folder is not loaded, but quite a large part of the modules are still uploaded to the hosting. If you create a new project and deploy it on Heroku, you will see this in the app settings on the hosting:
58
I assume 90% of these 63 megabytes are modules necessary for stable operation of node.

We do hope to add soon more smart clean up :slight_smile:

Currently for example we install all the database drivers for MySQL, Microsoft SQL, Postgres and SQLite and those are huge packages while you usually use just one. So we hope to improve that soon and make it much smarter.

1 Like

This guy reduced the size of node-modules from 249MB to 120MB by using modeclean, node-prune and minify-all, details on the link, see the last comment https://stackoverflow.com/questions/47600994/automatically-minify-all-node-modules
George, can confirm that is the solution or have other ones?
Is skypack https://www.skypack.dev ESM modules repository a good way to have minimal node_modules size?
In the meantime, the nodejs team recommends to start porting CJS to ESM (see https://twitter.com/MylesBorins/status/1329163754639155201).

We are talking about node modules here that are used server side in NodeJS not in a browser.

So there is no need to minify those or make them available with cdn.

They are just on your server and are running locally.

In my case some modules are required indeed. Got error Cannot find module 'universalify' and stuff... that are required from node_modules... writing while waiting them being transferred to the server :sweat_smile: