Vishal Gulati Vishal Gulati - 1 month ago 6
Node.js Question

Do we need to push node_modules on bitbucket

While pushing an angular2 app on bitbucket, do we need to also push node_modules and typings folder along? I have to deply the app on azure. As far as I understood from various articles that when we deploy on Azure then it runs npm install itself hence node_modules and typings folder get created. Please share on this.

Answer

Per Azure's documentation,

Azure Cloud Services expect all modules to be installed on the development environment, and the node_modules directory to be included as part of the deployment package. It is possible to enable support for installing modules using package.json or npm-shrinkwrap.json files on Cloud Services, however this requires customization of the default scripts used by Cloud Service projects. For an example of how to accomplish this, see Azure Startup task to run npm install to avoid deploying node modules

They also expand on this issue:

When deploying the node_modules directory as part of your application, it will increase the size of the deployment compared to using a package.json or npm-shrinkwrap.json file; however, it does guarantee that the version of the modules used in production are the same as those used in development.

In terms of code management, there are conflicting positions whether the node_modules folder should or shouldn't be submitted to version control. What I can say is that after the left-pad incident more and more people have been trending towards the "should commit" direction, myself included.

Should you want to follow this road, I suggest you take a look at both shrinkwrap, which locks the versions of the packages your dependencies themselves depend on, and shrinkpack which saves the actual packages as .tar to avoid noisy commit changes.

Comments