{"id":23137,"date":"2024-02-15T01:13:53","date_gmt":"2024-02-15T00:13:53","guid":{"rendered":"https:\/\/nelkodev.com\/blog\/administracion-del-archivo-package-json-en-npm\/"},"modified":"2024-06-03T18:44:17","modified_gmt":"2024-06-03T17:44:17","slug":"administracion-del-archivo-package-json-en-npm","status":"publish","type":"post","link":"https:\/\/nelkodev.com\/en\/blog\/package-json-file-management-in-npm\/","title":{"rendered":"Managing the package.json file in npm"},"content":{"rendered":"<p>The package.json file is a fundamental part of any project developed in JavaScript. It is responsible for storing and managing information about the project, its dependencies and other relevant details. In this guide we will teach you how to manage and use the package.json file in npm.<\/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\/package-json-file-management-in-npm\/#%C2%BFQue_es_el_archivo_packagejson\" >What is package.json file?<\/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\/package-json-file-management-in-npm\/#%C2%BFComo_crear_un_archivo_packagejson\" >How to create a package.json file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nelkodev.com\/en\/blog\/package-json-file-management-in-npm\/#%C2%BFComo_editar_el_archivo_packagejson\" >How to edit package.json file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nelkodev.com\/en\/blog\/package-json-file-management-in-npm\/#%C2%BFComo_instalar_dependencias_desde_el_archivo_packagejson\" >How to install dependencies from package.json file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/nelkodev.com\/en\/blog\/package-json-file-management-in-npm\/#%C2%BFComo_ejecutar_scripts_desde_el_archivo_packagejson\" >How to run scripts from package.json file?<\/a><\/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\/package-json-file-management-in-npm\/#Preguntas_frecuentes\" >Frequently asked questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFQue_es_el_archivo_packagejson\"><\/span>What is package.json file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The package.json file is a configuration file used by npm, the most popular JavaScript package manager. This file is essential in any JavaScript project as it contains important metadata such as the project name, its version, required dependencies, and scripts available for execution.<\/p>\n<p>The package.json file also allows developers to specify the dependencies their project requires. This makes it easier to install and manage additional packages necessary for the correct functioning of the application.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFComo_crear_un_archivo_packagejson\"><\/span>How to create a package.json file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Creating a package.json file is a simple process. To get started, you need to open a terminal and navigate to the root directory of your project. Then run the following command:<\/p>\n<pre>\nnpm init\n<\/pre>\n<p>This will open an interactive wizard that will guide you through creating the package.json file. The wizard will ask you questions about basic project information, such as name, version, description, and author. You can also skip the wizard and create the empty package.json file using the following command:<\/p>\n<pre>\nnpm init -y\n<\/pre>\n<p>This command will create a package.json file with the default values.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFComo_editar_el_archivo_packagejson\"><\/span>How to edit package.json file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once you&#039;ve created the package.json file, you may need to edit it to add or modify information. You can open the file with any text editor or you can use the following command in the terminal:<\/p>\n<pre>\nnpm edit\n<\/pre>\n<p>This will open the package.json file in your operating system&#039;s default editor. Here you can make any necessary changes and save your changes when you&#039;re done.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFComo_instalar_dependencias_desde_el_archivo_packagejson\"><\/span>How to install dependencies from package.json file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One of the advantages of the package.json file is that it makes it easy to install dependencies necessary for your project. To install all the dependencies listed in the package.json file, simply run the following command in the terminal:<\/p>\n<pre>\nnpm install\n<\/pre>\n<p>This will install all the dependencies specified in the package.json file into the node_modules directory of your project.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFComo_ejecutar_scripts_desde_el_archivo_packagejson\"><\/span>How to run scripts from package.json file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The package.json file also allows you to define custom scripts that can be run with the npm run command. These scripts are useful for common tasks, such as running tests, compiling code, or starting the development server.<\/p>\n<p>To run a script defined in the package.json file, use the following command:<\/p>\n<pre>\nnpm run script_name\n<\/pre>\n<p>Replace &quot;script_name&quot; with the name of the script you want to run. For example, if you have a script called &quot;start&quot; defined in the package.json file, you can run it with:<\/p>\n<pre>\nnpm run start\n<\/pre>\n<p>These are just some basics about managing the package.json file in npm. It is a powerful tool that helps you manage the dependencies and scripts of your JavaScript project. Be sure to read the official npm documentation to learn more about all the options available.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Preguntas_frecuentes\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>What happens if I delete the package.json file?<\/strong><\/p>\n<p>If you delete the package.json file, you will lose all information related to your project, including dependencies and defined scripts. It is recommended to have a backup copy of the file or use a version control tool to avoid loss of information.<\/p>\n<p><strong>Can I have multiple package.json files in a project?<\/strong><\/p>\n<p>No, there should only be one package.json file in the root directory of your project. However, you can have additional package.json files in subdirectories if your project is structured that way.<\/p>\n<p><strong>Where can I find more information about the package.json file?<\/strong><\/p>\n<p>You can find more detailed information about the package.json file in the official npm documentation. You can also check out online tutorials and guides to learn more about how to get the most out of this tool.<\/p>\n<p>I hope this guide helped you understand how to manage and use the package.json file in npm. If you have any questions or need more information, do not hesitate to contact me. Good luck in your JavaScript projects!<\/p>","protected":false},"excerpt":{"rendered":"<p>The package.json file is a fundamental part of any project developed in JavaScript. It is responsible for storing and managing information about the project, its dependencies, and other relevant details. In this guide, we will teach you how to manage and use the package.json file in npm. What is the package.json file? The package.json file is a file that stores and stores information about the project, its dependencies, and other relevant details. [\u2026]<\/p>","protected":false},"author":1,"featured_media":23138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[420,2207,1125],"tags":[720,964,205,172,2208,613,965],"class_list":["post-23137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-nodejs","category-npm","tag-administracion","tag-archivo","tag-blog","tag-del","tag-nodejs","tag-npm","tag-package-json"],"_links":{"self":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/23137","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=23137"}],"version-history":[{"count":0,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/23137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media\/23138"}],"wp:attachment":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media?parent=23137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/categories?post=23137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/tags?post=23137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}