{"id":15980,"date":"2024-10-04T06:45:58","date_gmt":"2024-10-04T05:45:58","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=15980"},"modified":"2024-10-04T06:46:00","modified_gmt":"2024-10-04T05:46:00","slug":"npm-commands","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/","title":{"rendered":"Most Common NPM Commands: A Quick Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What is NPM?<\/h2>\n\n\n\n<p>NPM (<a href=\"https:\/\/www.milesweb.co.uk\/blog\/technology-hub\/what-is-npm\/\">Node Package Manager<\/a>) is a package manager for JavaScript that effectively manages the packages (modules) of your Node.js projects. With the use of NPM, developers install, update, and manage dependencies and can share and publish their own packages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Features of NPM<\/h2>\n\n\n\n<p>There are various features of NPM, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Workspaces:<\/strong> NPM helps to work on multiple projects in a single workspace.<\/li>\n\n\n\n<li><strong>Private Packages: <\/strong>With NPM, users can package privately and share publicly to a private NPM registry.<\/li>\n\n\n\n<li><strong>Version Ranges:<\/strong> Specify version ranges for your dependencies so you can avoid undesirable updates.<\/li>\n\n\n\n<li><strong>NPM Scripts Lifecycle: <\/strong>NPM defines scripts that are run automatically at specific life cycles of a package, such as preinstall\/postinstall\/prepublish.<\/li>\n<\/ul>\n\n\n\n<p>Along with these, you can get numerous other NPM commands to fully control your JavaScript project and leverage the full power of packages available in the ecosystem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are NPM commands?<\/h2>\n\n\n\n<p>NPM commands are instructions executed through command lines that help in the management of packages or modules in JavaScript applications. By default, NPM acts as the package manager for Node.js, making it relatively easy to install and share libraries as well as tools for application in one&#8217;s projects.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Commonly Used NPM Commands<\/h2>\n\n\n\n<p>Given below is a comprehensive list of the most commonly used NPM commands along with their descriptions.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. npm init<\/h3>\n\n\n\n<p>This command initializes a new Node.js project by generating a package.json file containing metadata about the project and its dependencies.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm init<\/code><\/pre>\n\n\n\n<p>You can also run it in &#8220;default mode&#8221; by skipping the setup steps:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm init -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. npm install (or npm i)<\/h3>\n\n\n\n<p>This command installs all the dependencies listed in your package.json file. It also allows you to install specific packages globally or locally within a project.<\/p>\n\n\n\n<p><strong><em>Install dependencies:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm install<\/code><\/pre>\n\n\n\n<p><strong><em>Install a specific package locally:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm install &lt;package-name&gt;<\/code><\/pre>\n\n\n\n<p><strong><em>Install a specific package globally:<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm install -g &lt;package-name&gt;<\/code><\/pre>\n\n\n\n<p><strong><em>Installation Global vs. Local Installations<\/em><\/strong><\/p>\n\n\n\n<p>npm install -g installs a package globally, permitting its usage through your application by all projects. The best practice, however, is to install a package in a project to avoid unwanted conflict and to be in control of the same dependency.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. npm install for specific package<\/h3>\n\n\n\n<p>With this command, developers can install a specific package and add it to the dependencies section of your package.json file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm install &lt;package-name&gt; --save<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. npm install specific packages for development<\/h3>\n\n\n\n<p>The given below command is useful in installing a specific package and adding it to the dependencies section of your package.json. This command is useful for packages required during development but not in production (for example, testing frameworks).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm install &lt;package-name&gt; --save-dev<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. npm uninstall (or npm rm)<\/h3>\n\n\n\n<p>This command removes a package from your project. It also removes the dependency from the package.json file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm uninstall &lt;package-name&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. npm update<\/h3>\n\n\n\n<p>As the name suggests, it can update all installed packages to their latest versions according to the version range specified in the package.json.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. npm outdated<\/h3>\n\n\n\n<p>This command returns information about the current version, the wanted version, and the latest version. Therefore, using this command, developers can get a list of packages that have newer versions available but are not installed yet in the package.json.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm outdated<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. npm run<\/h3>\n\n\n\n<p>With the run command, you can run a custom script specified in the scripts section of your package.json. You might use it to test, start servers, or bundle your files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm run &lt;script-name&gt;\nExample from package.json\njson\n&nbsp;{\n&nbsp;&nbsp;&nbsp;\"scripts\": {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"start\": \"node index.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"test\": \"jest\"\n&nbsp;&nbsp;&nbsp;}\n&nbsp;}<\/code><\/pre>\n\n\n\n<p>To run the script: npm run start<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>NPM Scripts<\/strong>: NPM scripts are an effortless way of automating the most common tasks within your project. You might easily define scripts in the scripts section of your package.json and run them with npm run. For example, you may have a script that boots up your development server, runs tests, or builds your project, to mention but a few.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">9. npm audit<\/h3>\n\n\n\n<p>It scans your project for any vulnerabilities in the libraries it uses and lets you know about them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm audit<\/code><\/pre>\n\n\n\n<p>There\u2019s another command to fix the vulnerabilities of the libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm audit fix&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">10. npm list<\/h3>\n\n\n\n<p>For beginners, the swallowing command is very useful. It displays the tree (a comprehensive list) of installed packages, listing all of your project&#8217;s dependencies in one place.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm list&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">11. npm cache clean<\/h3>\n\n\n\n<p>The NPM cache is where downloaded packages are stored. Sometimes, cleaning the cache solves issues with package installation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm cache clean --force&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">12. npm publish<\/h3>\n\n\n\n<p>You can publish packages available for others to install. The publishing takes place on the NPM registry.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm publish&nbsp;&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">13.&nbsp;npm version<\/h3>\n\n\n\n<p>Get the most used command to increment the version number of your project according to semantic versioning. It modifies the version field in package.json.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command: npm version &lt;update_type&gt;<\/code><\/pre>\n\n\n\n<p>The following commands are further used for specific needs:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Patch update: npm version patch<\/li>\n\n\n\n<li>Minor update: npm version minor<\/li>\n\n\n\n<li>Major update: npm version ma<\/li>\n<\/ul>\n\n\n\n<div class=\"vlt-box \">\n<div class=\"box-title\" style=\"background:#D5EAFF; color:#000\">Conclusion<\/div>\n<div class=\"box-content\">\n<p>NPM is a fantastic tool for managing JavaScript packages in any application, from smallest-sized projects to large applications. Of course, the commands are critical when dealing with dependency management, running scripts, and keeping the project updated; hence, we have listed all the essential commands for updating you in detail.<\/p>\n<p>Now that you&#8217;ve learned these commands, you will save more development workflow and can also ensure that the Node.js projects you work on run in the smoothest flow.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is NPM? NPM (Node Package Manager) is a package manager for JavaScript that effectively manages the packages (modules) of your Node.js projects. With the use of NPM, developers install, update, and manage dependencies and can share and publish their own packages. Features of NPM There are various features of NPM, such as: Along with [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[230],"tags":[],"class_list":["post-15980","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Most Common NPM Commands: A Quick Guide<\/title>\n<meta name=\"description\" content=\"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Most Common NPM Commands: A Quick Guide\" \/>\n<meta property=\"og:description\" content=\"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-04T05:45:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-04T05:46:00+00:00\" \/>\n<meta name=\"author\" content=\"Ujwala\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ujwala\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/\",\"name\":\"Most Common NPM Commands: A Quick Guide\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"datePublished\":\"2024-10-04T05:45:58+00:00\",\"dateModified\":\"2024-10-04T05:46:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/485f82549b85b9f4c82dc208c42964a8\"},\"description\":\"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Most Common NPM Commands: A Quick Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/485f82549b85b9f4c82dc208c42964a8\",\"name\":\"Ujwala\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d26ea4b9b2d83ae90b67f6bf5eefbca?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d26ea4b9b2d83ae90b67f6bf5eefbca?s=96&d=blank&r=g\",\"caption\":\"Ujwala\"},\"description\":\"My aim is to create enriching content on topics related to SEO, web hosting and social media. The idea is to elevate the readers to new levels of usability, accessibility and understanding.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/ujwala\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Most Common NPM Commands: A Quick Guide","description":"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/","og_locale":"en_GB","og_type":"article","og_title":"Most Common NPM Commands: A Quick Guide","og_description":"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2024-10-04T05:45:58+00:00","article_modified_time":"2024-10-04T05:46:00+00:00","author":"Ujwala","twitter_misc":{"Written by":"Ujwala","Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/","name":"Most Common NPM Commands: A Quick Guide","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"datePublished":"2024-10-04T05:45:58+00:00","dateModified":"2024-10-04T05:46:00+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/485f82549b85b9f4c82dc208c42964a8"},"description":"Get a thorough understanding of NPM commands for development. From package installation to script management, we have covered all.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/npm-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"Most Common NPM Commands: A Quick Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/485f82549b85b9f4c82dc208c42964a8","name":"Ujwala","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d26ea4b9b2d83ae90b67f6bf5eefbca?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d26ea4b9b2d83ae90b67f6bf5eefbca?s=96&d=blank&r=g","caption":"Ujwala"},"description":"My aim is to create enriching content on topics related to SEO, web hosting and social media. The idea is to elevate the readers to new levels of usability, accessibility and understanding.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/ujwala\/"}]}},"views":0,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/15980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=15980"}],"version-history":[{"count":1,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/15980\/revisions"}],"predecessor-version":[{"id":15981,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/15980\/revisions\/15981"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=15980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=15980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=15980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}