{"id":24075,"date":"2024-03-11T16:48:40","date_gmt":"2024-03-11T15:48:40","guid":{"rendered":"https:\/\/nelkodev.com\/blog\/administracion-de-la-carpeta-node_modules-en-proyectos-node-js\/"},"modified":"2024-06-03T18:43:55","modified_gmt":"2024-06-03T17:43:55","slug":"administracion-de-la-carpeta-node_modules-en-proyectos-node-js","status":"publish","type":"post","link":"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/","title":{"rendered":"Managing the node_modules folder in Node.js projects"},"content":{"rendered":"<p>Folder <code>node_modules<\/code> It is a fundamental directory in Node.js development projects. In this article, I will explain how to effectively manage this folder and how to optimize its performance in your Javascript projects.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ffffff;color:#ffffff\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ffffff;color:#ffffff\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFQue_es_la_carpeta_node_modules\" >What is node_modules folder?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFComo_administrar_la_carpeta_node_modules\" >How to manage node_modules folder?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#1_Utiliza_un_archivo_gitignore\" >1. Use a .gitignore file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#2_Utiliza_npm_scripts_para_instalar_dependencias\" >2. Use npm scripts to install dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#3_Actualiza_regularmente_las_dependencias\" >3. Regularly update dependencies<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#Optimizacion_del_rendimiento_de_la_carpeta_node_modules\" >Optimizing the performance of the node_modules folder<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#1_Utiliza_npm_ci_en_lugar_de_npm_install\" >1. Use npm ci instead of npm install<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#2_Utiliza_gestores_de_dependencias_alternativos\" >2. Use alternative dependency managers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#3_Utiliza_herramientas_de_optimizacion\" >3. Use optimization tools<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#Preguntas_frecuentes\" >Frequently asked questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFEs_necesario_guardar_la_carpeta_node_modules_en_mi_repositorio_git\" >Do I need to save the node_modules folder to my git repository?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFDebo_actualizar_manualmente_las_dependencias\" >Should I manually update dependencies?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFComo_puedo_gestionar_las_versiones_de_las_dependencias\" >How can I manage dependency versions?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/nelkodev.com\/en\/blog\/administration-of-the-node_modules-folder-in-node-js-projects\/#%C2%BFEs_posible_eliminar_dependencias_no_utilizadas\" >Is it possible to remove unused dependencies?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFQue_es_la_carpeta_node_modules\"><\/span>What is node_modules folder?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Folder <code>node_modules<\/code> is a directory where all the dependencies of a Node.js project are stored. When you install a package or library using the Node.js package manager, npm, the dependencies are downloaded and stored in this folder.<\/p>\n<p>The folder structure <code>node_modules<\/code> It is hierarchical and each package has its own directory in which the files necessary for its operation are stored. This allows you to have more organized control over your project&#039;s dependencies.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFComo_administrar_la_carpeta_node_modules\"><\/span>How to manage node_modules folder?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Folder management <code>node_modules<\/code> can be a challenge on large scale projects. Here are some best practices to keep this folder under control:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Utiliza_un_archivo_gitignore\"><\/span>1. Use a .gitignore file<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is important to add the folder <code>node_modules<\/code> to the file <code>.gitignore<\/code> to prevent files from being uploaded to your git repository. This will save space in your repository and avoid performance issues.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Utiliza_npm_scripts_para_instalar_dependencias\"><\/span>2. Use npm scripts to install dependencies<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Instead of directly executing the command <code>npm install<\/code>, it is recommended to use npm scripts to install dependencies. This will allow you to customize package installation and have greater control over versions and configurations.<\/p>\n<pre><code>&quot;scripts&quot;: { &quot;install&quot;: &quot;npm ci&quot; }\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"3_Actualiza_regularmente_las_dependencias\"><\/span>3. Regularly update dependencies<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is important to keep dependencies up to date in your project. To do this, you can use the command <code>npm outdated<\/code> to check for outdated versions of your packages and then run <code>npm update<\/code> to update them.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Optimizacion_del_rendimiento_de_la_carpeta_node_modules\"><\/span>Optimizing the performance of the node_modules folder<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As your project grows, the folder <code>node_modules<\/code> it can become very large and affect the performance of your application. Here are some strategies to optimize the performance of this folder:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Utiliza_npm_ci_en_lugar_de_npm_install\"><\/span>1. Use npm ci instead of npm install<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The command <code>npm ci<\/code> install the dependencies directly from the <code>package-lock.json<\/code> and ensures a faster and more consistent installation. Make sure to use <code>npm ci<\/code> rather <code>npm install<\/code> in your production environments.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Utiliza_gestores_de_dependencias_alternativos\"><\/span>2. Use alternative dependency managers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>There are alternative dependency managers to npm that can improve folder performance <code>node_modules<\/code>. For example, yarn is known for its speed and efficiency in installing packages. You can try different managers and evaluate which one best suits your needs.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Utiliza_herramientas_de_optimizacion\"><\/span>3. Use optimization tools<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>There are various tools that you can use to optimize folder performance <code>node_modules<\/code>. For example, you can use the tool <a href=\"https:\/\/www.npmjs.com\/package\/webpack-bundle-analyzer\" target=\"_blank\" rel=\"noopener nofollow\">Webpack Bundle Analyzer<\/a> to analyze the size of your bundles and detect unnecessary or very large dependencies.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Preguntas_frecuentes\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%C2%BFEs_necesario_guardar_la_carpeta_node_modules_en_mi_repositorio_git\"><\/span>Do I need to save the node_modules folder to my git repository?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No, it is recommended to add the folder <code>node_modules<\/code> to the file <code>.gitignore<\/code> to avoid uploading it to your repository. It is possible to install the dependencies using the file <code>package.json<\/code> and the command <code>npm install<\/code> o <code>npm ci<\/code>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%C2%BFDebo_actualizar_manualmente_las_dependencias\"><\/span>Should I manually update dependencies?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is advisable to regularly update your project&#039;s dependencies, as this will allow you to benefit from new features and bug fixes. You can use the command <code>npm outdated<\/code> to check for outdated versions and then run <code>npm update<\/code> to update them.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%C2%BFComo_puedo_gestionar_las_versiones_de_las_dependencias\"><\/span>How can I manage dependency versions?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can manage the versions of dependencies using the file <code>package.json<\/code>. In this file, you can indicate specific versions of dependencies or use version ranges. You can consult the npm documentation for more information on version management.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%C2%BFEs_posible_eliminar_dependencias_no_utilizadas\"><\/span>Is it possible to remove unused dependencies?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use tools like <a href=\"https:\/\/www.npmjs.com\/package\/npm-check\" target=\"_blank\" rel=\"noopener nofollow\">npm-check<\/a> to detect and remove unused dependencies in your project. This can help you reduce the folder size <code>node_modules<\/code> and improve the performance of your application.<\/p>\n<p>I hope this article helped you understand how to manage and optimize the folder <code>node_modules<\/code> in your Node.js projects. If you have any questions, feel free to contact me through my contact page. <a href=\"https:\/\/nelkodev.com\/en\/contact\/\" target=\"_blank\" rel=\"noopener\">contact<\/a>. I also invite you to visit my <a href=\"https:\/\/nelkodev.com\/en\/portfolio\/\" target=\"_blank\" rel=\"noopener\">briefcase<\/a> to discover other useful resources related to Javascript in Spanish.<\/p>","protected":false},"excerpt":{"rendered":"<p>The node_modules folder is a fundamental directory in Node.js development projects. In this article, I will explain how to effectively manage this folder and how to optimize its performance in your Javascript projects. What is the node_modules folder? The node_modules folder is a directory where all the dependencies of a Node.js project are stored.<\/p>","protected":false},"author":1,"featured_media":24076,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[420,2207,1125],"tags":[720,205,1195,1194,1193,2208,613,401],"class_list":["post-24075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-nodejs","category-npm","tag-administracion","tag-blog","tag-carpeta","tag-node_modules","tag-node-js","tag-nodejs","tag-npm","tag-proyectos"],"_links":{"self":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/24075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/comments?post=24075"}],"version-history":[{"count":0,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/24075\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media\/24076"}],"wp:attachment":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media?parent=24075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/categories?post=24075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/tags?post=24075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}