Reputation: 551
We are running multiple node.js micro services. A part of our deployment process has an "unzip task" and it takes over 10minutes because of the amount of files in the node module folder. We cant run npm install on the servers on which those micro services are running on because of security issues.
I was wondering if there are any common ways to reduce the amount of files and maybe the dependencies in the node module folder? Because even when I reduce the size of the folder by tens of mega bytes the amount of files still remains very big.
Upvotes: 1
Views: 464
Reputation: 162
It's possible to bundle the entire project into a single file and/or executable. To bundle your project, you use ncc and execute it like this:
ncc build input.js -o dist
This will create the index.js in the dirst folder, with all other files bundled together. It's also possible to require native node files. It might be an issue if you have dynamic requires in your code base.
To create a single binary, you can use pkg. It supports different node versions and builds cross-platform:
pkg index.js
Create files "index-linux", "index-macos" and "index-win.exe".
Of course, you can combine both packages nicely. This should reduce the amount of files you want to deploy. Of course, this makes debugging through it rather difficult. So keep that in mind when going that route!
Upvotes: 1