{"id":16504,"date":"2021-09-16T14:30:51","date_gmt":"2021-09-16T14:30:51","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16504"},"modified":"2025-04-28T08:02:32","modified_gmt":"2025-04-28T08:02:32","slug":"what-is-npm","status":"publish","type":"post","link":"\/in\/tutorials\/what-is-npm","title":{"rendered":"What Is npm? A Basic Introduction to Node Package Manager for Beginners"},"content":{"rendered":"<p>With npm, JavaScript developers can discover and install code packages into their networking applications or server-side projects.<\/p><p>A <strong>node.js<\/strong> package is a directory with one or more JavaScript modules or libraries used to add various features to applications or scripts. Without packages, a developer or software engineer has to write new code for each functionality that their project needs.<\/p><p>This article will explain how npm works and teach you how to start a project with it and install additional packages.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/HTML-Cheatsheet.pdf\" target=\"_blank\" rel=\"noopener\">Download complete HTML cheat sheet<\/a><\/p><p>\n\n\n\n\n\n<div class=\"protip\">\n                    <h2 class=\"featured-snippet title\">What Is npm?<\/h2>\n                    <p>Node package manager (npm) is one of the largest software registries in the world. It comes bundled with node.js, an open-source server environment.<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-does-npm-work\">How Does npm Work?<\/h2><p>Here are the three defining roles of npm:<\/p><ul class=\"wp-block-list\">\n<li><strong>Repository <\/strong>&ndash; npm is a widely used <a href=\"https:\/\/npmjs.com\/\" target=\"_blank\" rel=\"noopener\">repository<\/a> for publishing open-source Node projects, where developers can share their source code with other npm users. <strong>Angular<\/strong>, <strong><a href=\"\/in\/tutorials\/what-is-react\">React<\/a><\/strong>, and <a href=\"https:\/\/www.npmjs.com\/package\/jquery\" target=\"_blank\" rel=\"noopener\"><strong>jQuery<\/strong><\/a> are some of the packages you can download from an npm repository.<\/li>\n\n\n\n<li><strong>Command-line interface (CLI)<\/strong> &ndash; developers run the npm <a href=\"\/in\/tutorials\/what-is-cli\">CLI<\/a> from a terminal or a command-line tool to install or uninstall packages and manage versions or dependencies.<\/li>\n\n\n\n<li><strong>Registry <\/strong>&ndash; any package or module you install using the npm CLI is downloaded from the <a href=\"https:\/\/registry.npmjs.org\/\" target=\"_blank\" rel=\"noopener\">npm public registry<\/a>, the JavaScript software database.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-what-is-package-json\">What Is package.json?<\/h2><p>Every npm project contains <strong>package.json<\/strong>, a file located in the root directory. It contains the metadata of npm projects or packages, such as package versions and contributors.<\/p><p>The <strong>package.json<\/strong> file simplifies identifying, managing, and installing a package. That&rsquo;s why it&rsquo;s essential to include <strong>package.json<\/strong> before publishing projects on the npm registry.<\/p><p>Here is an example of what a <strong>package.json<\/strong> file contains:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"hostinger-npm\",\n  \"version\": \"1.0.0\",\n  \"description\": \"npm guide for beginner\",\n  \"main\": \"beginner-npm.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"dependencies\": {\n    \"express\": \"^4.17.1\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https:\/\/github.com\/hostinger\/example.git\"\n  },\n  \"keywords\": [\n    \"npm\",\n    \"example\",\n    \"basic\"\n  ],\n  \"author\": \"Hostinger International\",\n  \"license\": \"MIT\",\n}<\/pre><p>To help you understand <strong>package.json<\/strong>, we&rsquo;ll go over the most important lines from the previous example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"name\": \"hostinger-npm\",<\/pre><p>The line above defines the <strong>package name<\/strong>. It should be less than 214 characters and consist of lowercase letters only. If you want to publish a tool on the npm registry, its name should differ from any existing packages.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"version\": \"1.0.0\",<\/pre><p>The <strong>version <\/strong>specifies the current version of your project, and it should follow the <a href=\"https:\/\/docs.npmjs.com\/about-semantic-versioning\" target=\"_blank\" rel=\"noopener\">semantic versioning rules<\/a>.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"description\": \"npm guide for beginner\",<\/pre><p>Include the package information in the<strong> description <\/strong>line to help users discover your project on the npm registry.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"main\": \"beginner-npm.js\",<\/pre><p>The <strong>main <\/strong>field specifies the entry point or main file of your project. If this property is left blank, npm will automatically set its value to <strong>index.js<\/strong>.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n},<\/pre><p>The <strong>scripts <\/strong>property contains commands that run tasks for your project. An npm user can take advantage of this field to pass arguments to the CLI without retyping them.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"dependencies\": {\n  \"express\": \"^4.16.4\"\n},<\/pre><p>This field lists all the <strong>dependencies <\/strong>or packages used in the project. When you install a tool using the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm install<\/code> command, that project will be automatically inserted here.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"repository\": {\n  \"type\": \"git\",\n  \"url\": \"https:\/\/github.com\/hostinger\/example.git\"\n},<\/pre><p>The <strong>repository <\/strong>property contains the URL of the source code. In this example, <a href=\"\/in\/tutorials\/what-is-github\">GitHub<\/a> is the package location, and <a href=\"\/in\/tutorials\/git-tutorial\">Git<\/a> is the version control system.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"keywords\": [\n  \"npm\",\n  \"example\",\n  \"basic\"\n],<\/pre><p>This field includes an array of <strong>keywords <\/strong>related to what the package does, helping npm users locate packages via searches. Omit this property if you won&rsquo;t publish the project on the npm registry.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"author\": \"Hostinger International\",<\/pre><p>Use the <strong>author <\/strong>property to state the creator of the project.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"license\": \"MIT\",<\/pre><p>This line defines the <strong>license <\/strong>of the npm project, letting people know if they can use it without any restrictions.<\/p><p>For information on the other fields of <strong>package.json<\/strong>, refer to <a href=\"https:\/\/docs.npmjs.com\/files\/package.json\" target=\"_blank\" rel=\"noopener\">package.json&rsquo;s official documentation<\/a>.<\/p><h2 class=\"wp-block-heading\" id=\"h-what-are-dependencies-and-devdependencies\">What Are Dependencies and devDependencies?<\/h2><p>Dependencies and devDependencies are fields in <strong>package.json<\/strong> that list all packages a project depends on.<\/p><p>The dependency field includes all of the third-party packages that are required for your project to work.<\/p><p>On the other hand, the devDependency property contains packages that are only necessary during development.<\/p><p>Dependencies and devDependencies are installed via the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm install<\/code> command with the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">--save<\/code> and <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">--save-dev<\/code> flags.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-npm-modules-and-start-projects\">How to Install npm Modules and Start Projects?<\/h2><p>Before using npm, make sure that <strong><a href=\"\/in\/tutorials\/what-is-node-js\">node.js<\/a><\/strong> is installed. To do so, open your terminal and run this command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">node -v<\/pre><p>The terminal window should display the <strong>node.js<\/strong> version installed on your system:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">V14.17.5  <\/pre><p>Do the same for npm by using the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm -v<\/pre><p>It should also return a version number like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">6.14.14<\/pre><p>If <strong>node.js<\/strong> hasn&rsquo;t been installed yet, download it from the <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\">official website<\/a>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/node-js.png\"><img decoding=\"async\" width=\"1024\" height=\"433\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/node-js-1024x433.png\" alt=\"node.js official website\" class=\"wp-image-36556\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/node-js.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/node-js-300x127.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/node-js-150x63.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/node-js-768x325.png 768w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/node-js-1536x649.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>In the following sections, we&rsquo;ll discuss some of the basic npm commands.<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>If you are using Hostinger VPS, you can choose a <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1583571-what-are-the-available-operating-systems-for-vps\" target=\"_blank\" rel=\"noopener\">operating system template<\/a> with Node.js already pre-installed. To learn more about this option, visit Hostinger's <a href=\"\/in\/vps\/nodejs-hosting\">Node.js VPS<\/a> page. <\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-initializing-a-project-with-npm\">Initializing a Project with npm<\/h3><p>To start a new project, run the following command from the npm CLI:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm init<\/pre><p>This command will create a project&rsquo;s <strong>package.json<\/strong> file in the current directory.<\/p><p>After running the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm init<\/code> command, the terminal will display this information:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">This utility will walk you through creating a package.json file.\nIt only covers the most common items, and tries to guess sensible defaults.\n\nSee `npm help init` for definitive documentation on these fields\nand exactly what they do.\n\nUse `npm install &lt;pkg&gt;` afterwards to install a package and\nsave it as a dependency in the package.json file.\n\nPress ^C at any time to quit.\npackage name: (test-npm)<\/pre><p>You&rsquo;ll be prompted to input the project information in the following order:<\/p><ul class=\"wp-block-list\">\n<li>Package name<\/li>\n\n\n\n<li>Initial version<\/li>\n\n\n\n<li>Description<\/li>\n\n\n\n<li>Entry point<\/li>\n\n\n\n<li>Test command<\/li>\n\n\n\n<li>Git repository<\/li>\n\n\n\n<li>Keywords<\/li>\n\n\n\n<li>Author<\/li>\n\n\n\n<li>License<\/li>\n<\/ul><p>Respond to each of the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm init<\/code> prompts by typing in custom values before pressing <strong>Enter<\/strong>. Alternatively, hit <strong>Enter<\/strong> without entering anything to keep the default values or the ones in parentheses.<\/p><p>Here&rsquo;s an example of how we fill the package information:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name: (test-npm)hostinger-npm\nversion: (1.0.0)1.0.0\ndescription: npm guide for beginner\nentry point: (index.js) beginner-npm.js\ntest command:\ngit repository:\nkeywords: npm, example, beginner\nauthor: Hostinger International\nlicense: (ISC) MIT<\/pre><p>After entering all the project details, <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm init<\/code> will display the preview of the <strong>package.json<\/strong> file like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"hostinger-npm\",\n  \"version\": \"1.0.0\",\n  \"description\": \"npm guide for beginner\",\n  \"main\": \"beginner-npm.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [\n    \"npm\",\n    \"example\",\n    \"beginner\"\n  ],\n  \"author\": \"Hostinger International\",\n  \"license\": \"MIT\", \n}\n\nIs this OK? (yes)<\/pre><p>Type <strong>yes<\/strong> and press <strong>Enter<\/strong> to save the <strong>package.json <\/strong>file. You can modify it later by editing the file or running the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm init<\/code> command again.<\/p><p>If you want to generate the <strong>package.json<\/strong> file with default values without responding to the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">npm init<\/code> prompts, use this command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm init --yes<\/pre><p>npm will create a <strong>package.json <\/strong>file with the default values, like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"mymac-MacBok-Pro\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\"\n}<\/pre><p>Once you have created the <strong>package.json<\/strong> file, you can add any node packages to the project.<\/p><h3 class=\"wp-block-heading\" id=\"h-installing-npm-modules-in-your-project\">Installing npm Modules in Your Project<\/h3><p>It&rsquo;s essential to learn how to install a package when getting started with npm.<\/p><p>To add a package to your project, run either of these commands:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt;\n\/\/ OR\nnpm i &lt;package-name&gt;<\/pre><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>In the commands above, replace  with the name of the module you want to install.<\/p>\n                <\/div>\n\n\n\n<\/p><p>For example, if you wish to install <a href=\"https:\/\/www.npmjs.com\/package\/express\" target=\"_blank\" rel=\"noopener\">express<\/a>, a popular web framework that simplifies standard web development processes, use the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install express<\/pre><p>This command will install the express module in the <strong>node_modules<\/strong> folder in the root project directory. Note that <strong>node_modules<\/strong> will only appear after installing the first package.<\/p><p>If the package is successfully installed, the terminal will display a message like this:<\/p><figure class=\"wp-block-image size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/express-module.png\"><img decoding=\"async\" width=\"870\" height=\"117\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/express-module.png\" alt=\"Terminal message: express successfully installed.\" class=\"wp-image-36558\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/express-module.png 870w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/express-module-300x40.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/express-module-150x20.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/express-module-768x103.png 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><\/figure><p>The <strong>package.json <\/strong>will also include the module in the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">dependencies<\/code> field:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"hostinger-npm\",\n  \"version\": \"1.0.0\",\n  \"description\": \"npm guide for beginner\",\n  \"main\": \"beginner-npm.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [\n    \"npm\",\n    \"example\",\n    \"basic\"\n  ],\n  \"author\": \"Hostinger International\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"express\": \"^4.17.1\"\n  }\n}<\/pre><h3 class=\"wp-block-heading\" id=\"h-installing-a-package-as-a-development-dependency\">Installing a Package As a Development Dependency<\/h3><p>To install any tools that will only be used in the <a href=\"\/in\/tutorials\/development-environment\">development environment<\/a>, use the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt; --save-dev<\/pre><p>For example, you may want to use <a href=\"https:\/\/www.npmjs.com\/package\/nodemon\" target=\"_blank\" rel=\"noopener\">nodemon<\/a> to reload your project when any file changes. To install this tool, type this into the terminal:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install nodemon --save-dev <\/pre><p>Once nodemon is installed, the terminal will show this message:<\/p><figure class=\"wp-block-image size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/nodemon-installed.png\"><img decoding=\"async\" width=\"856\" height=\"201\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/nodemon-installed.png\" alt=\"Terminal message showing nodemon was successfully installed.\" class=\"wp-image-36557\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/nodemon-installed.png 856w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/nodemon-installed-300x70.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/nodemon-installed-150x35.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/nodemon-installed-768x180.png 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><\/figure><p>The npm will also add the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">devDependencies<\/code> section with the new data to the <strong>package.json<\/strong> file like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"hostinger-npm\",\n  \"version\": \"1.0.0\",\n  \"description\": \"npm guide for beginner\",\n  \"main\": \"beginner-npm.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [\n    \"npm\",\n    \"example\",\n    \"basic\"\n  ],\n  \"author\": \"Hostinger International\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"express\": \"^4.17.1\"\n  }\n  \"devDependencies\": {\n    \"nodemon\": \"^2.0.12\"\n  }\n}<\/pre><h3 class=\"wp-block-heading\" id=\"h-installing-a-module-globally-on-your-system\">Installing a Module Globally on Your System<\/h3><p>In case you want to install an npm package to be used from the command line, enter either of the following commands:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt; --global\n\/\/ OR\nnpm i &lt;package-name&gt; -g<\/pre><p>Be sure to replace the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;package-name&gt;<\/code> with the module name.<\/p><h3 class=\"wp-block-heading\" id=\"h-updating-npm\">Updating npm<\/h3><p>To keep your code and tools secure and stable, regularly update local and global packages downloaded from the npm registry.<\/p><p>Before updating any npm package, check whether any of them are outdated. You can check which npm packages in your project or system have updates available by running this command from the root directory:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm outdated<\/pre><p>To check for outdated global packages in the system, run the following command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm outdated -g --depth=0<\/pre><p>After getting the list of outdated modules, you can either update all the packages or just one of them.<\/p><p>To update all the packages in your project, run this from the command line:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm update<\/pre><p>To update a single module, input this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm update &lt;package-name&gt;<\/pre><p>Remember to replace <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;package-name&gt;<\/code> with the name of the package you want to update.<\/p><p>To update all global packages in the system, run the command below:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm update -g<\/pre><p>In order to update a single global package, enter the following command, replacing <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;package-name&gt;<\/code> with the module name:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm update -g &lt;package-name&gt;<\/pre><p>To update your Node package manager itself, run this command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install npm@latest -g<\/pre><p>Once the latest version of npm has been installed, the terminal window will display a message like this:<\/p><figure class=\"wp-block-image size-full\"><a href=\"\/in\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/latest-npm.png\"><img decoding=\"async\" width=\"599\" height=\"55\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/09\/latest-npm.png\" alt=\"Terminal message showing the latest version of npm has been installed.\" class=\"wp-image-36555\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/latest-npm.png 599w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/latest-npm-300x28.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2021\/09\/latest-npm-150x14.png 150w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/a><\/figure><p>For other npm CLI commands, check out <a href=\"https:\/\/docs.npmjs.com\/cli\/v7\/commands\" target=\"_blank\" rel=\"noreferrer noopener\">npm&rsquo;s command documentation<\/a>.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a href=\"\/in\/web-hosting\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/11\/Web-hosting_in-text-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>npm is a popular package manager that lets JavaScript developers share and deploy useful packages quickly and easily.<\/p><p>Every npm project contains a file called<strong> package.json <\/strong>in its root directory. This file includes the project&rsquo;s metadata, which lets anyone find the module on the npm repository.<\/p><p>Aside from containing the critical project information, <strong>package.json<\/strong> also stores the list of the project&rsquo;s dependencies required for a project to function.<\/p><p>Moreover, packages developers have installed to assist them during the development process will be included in the <strong>package.json <\/strong>under devDependencies.<\/p><p>Here is the overview of npm commands to help you get started and perform basic tasks with this package manager:<\/p><ul class=\"wp-block-list\">\n<li><strong>Check the npm version:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm -v<\/pre><ul class=\"wp-block-list\">\n<li><strong>Initialize a project:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm init<\/pre><ul class=\"wp-block-list\">\n<li><strong>Install modules:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt;<\/pre><ul class=\"wp-block-list\">\n<li><strong>Install a package as a development dependency:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt; --save-dev<\/pre><ul class=\"wp-block-list\">\n<li><strong>Install a module globally on the system:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install &lt;package-name&gt; --global<\/pre><ul class=\"wp-block-list\">\n<li><strong>Update all packages in a project:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm update<\/pre><ul class=\"wp-block-list\">\n<li><strong>Update the latest version of npm:<\/strong><\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">npm install npm@latest -g<\/pre><p>We hope this article has helped you understand what npm is and provided some pointers on how to start working with it. Feel free to leave a comment below if you have any questions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With npm, JavaScript developers can discover and install code packages into their networking applications or server-side projects. A node.js package is a directory with one or more JavaScript modules or libraries used to add various features to applications or scripts. Without packages, a developer or software engineer has to write new code for each functionality [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/what-is-npm\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":156,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22597,22599],"tags":[],"class_list":["post-16504","post","type-post","status-publish","format-standard","hentry","category-website","category-website-development"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/what-is-npm","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/o-que-e-npm","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/quest-ce-que-npm","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/que-es-npm","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/apa-itu-npm","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/what-is-npm","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/what-is-npm-a-basic-introduction-for-beginners","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/what-is-npm-a-basic-introduction-for-beginners","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-es-npm","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-es-npm","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/que-es-npm","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/o-que-e-npm","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/what-is-npm","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/what-is-npm","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/what-is-npm","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/what-is-npm","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/156"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=16504"}],"version-history":[{"count":30,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16504\/revisions"}],"predecessor-version":[{"id":101677,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/16504\/revisions\/101677"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=16504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=16504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=16504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}