{"id":6907,"date":"2021-03-29T10:05:38","date_gmt":"2021-03-29T10:05:38","guid":{"rendered":"https:\/\/codoid.com\/?p=6907"},"modified":"2022-02-04T18:59:22","modified_gmt":"2022-02-04T18:59:22","slug":"basic-npm-commands","status":"publish","type":"post","link":"https:\/\/codoid.com\/automation-testing\/basic-npm-commands\/","title":{"rendered":"Basic npm Commands"},"content":{"rendered":"<p>Even the smallest hiccups like package installation errors can be a bane to your productivity. In this blog article, we have listed some of the basic npm commands which are used by developers and software testers regularly to resolve package installation errors and to even upgrade existing npm packages. As a software testing company, we are experts in <a href=\"https:\/\/codoid.com\/\">automation testing services<\/a> using Protractor &#038; Jasmine frameworks.<\/p>\n<p>For one to manage npm packages effectively, one should be aware of the most common npm commands. So let\u2019s get the ball rolling with a few basic commands that have been categorized by their purpose.<\/p>\n<h3>Package Installation<\/h3>\n<p>To install a package in your current project using npm commands, you can make use of either of the codes given below:<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm install package-name -s\r\n<\/pre>\n<\/div>\n<p>or<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm install package-name\r\n<\/pre>\n<\/div>\n<p>Use the code given below to install a package under Development dependencies in your current project by using npm commands:<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm install package-name \u2014save-dev\r\n<\/pre>\n<\/div>\n<p>You can install a package globally using npm commands if a package dependency is not for the project by using the below code:<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm install package-name -g\r\n<\/pre>\n<\/div>\n<h3>Install a specific package version<\/h3>\n<p>Sometimes you might find yourself to be in a situation where you need to install a specific package version rather than the most latest version. But when you run the npm install command, it will only install the latest version of a package. The solution is easy, as you can install a specific package version by simply using the version number in the installation command as shown below.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm install package-name@version-number\r\n<\/pre>\n<\/div>\n<h3>Finding Outdated Packages<\/h3>\n<p>When the dependency list grows, it is a cumbersome job to find the outdated packages in a project. However, npm can make your job easy as it has a command to find the packages which can be upgraded.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm outdated\r\n<\/pre>\n<\/div>\n<p>When you run the above command, it will list the outdated packages from which you can find the version that you are looking for.<\/p>\n<h3>Clear npm Cache using npm commands<\/h3>\n<p>When a package installation doesn\u2019t go as expected, it may be because of an <a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">npm cache issue<\/a>. One best option would be to clear the cache and then execute the installation command again.<\/p>\n<p>Before clearing the npm cache, make sure to check how many cache entries are available by using the below code.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm cache verify\r\n<\/pre>\n<\/div>\n<p>Now you can clear the npm cache by using the below command.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm cache clean \u2014force\r\n<\/pre>\n<\/div>\n<h3>Audit Packages<\/h3>\n<p>Using vulnerable npm packages can make your project less secure. So it is crucial to perform a security check for all the available project packages. You can do so by running the below command.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nnpm audit\r\n<\/pre>\n<\/div>\n<p>Once the audit has run, it will list the vulnerable packages which are supposed to be removed to make your packages more secure.<\/p>\n<h3>Installing Minor &#038; Patch Releases<\/h3>\n<p>When you run the npm install command, it will install the packages which are mentioned in the package.json file. The npm install command can be used to install only the missing packages. But if you are looking to install recent minor versions using the npm install command, you have to prefix the caret (^) symbol before the package version in package.json. To install patch releases, you have to prefix the Tilde (~) symbol.<\/p>\n<h3>Conclusion<\/h3>\n<p>Auditing packages &#038; removing unused packages periodically will help avoid catastrophic failures when deploying code in a production environment. Node.js is a memory-efficient environment. When an automation test suite runs for a longer duration, you should optimize it by improving the script and using good packages.<\/p>\n<p>QA automation testers who are starting automation test scripting using JavaScript &#038; Node.js will find these basic npm commands very helpful. Being an automation testing company, we use Protractor, Selenium WebDriver, and Jasmine frameworks for web apps automation testing, and therefore in the subsequent blog articles, we will be publishing more on Protractor and automation test scripting using JavaScript &#038; Node.js. So make sure to keep an eye on our website so that you don\u2019t miss out on the upcoming blogs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Even the smallest hiccups like package installation errors can be a bane to your productivity. In this blog article, we have listed some of the basic npm commands which are used by developers and software testers regularly to resolve package installation errors and to even upgrade existing npm packages. As a software testing company, we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6910,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[182,179,20,11],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v20.3) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Basic npm Commands - Codoid<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Basic npm Commands\" \/>\n<meta property=\"og:description\" content=\"Even the smallest hiccups like package installation errors can be a bane to your productivity. In this blog article, we have listed some of the basic npm commands which are used by developers and software testers regularly to resolve package installation errors and to even upgrade existing npm packages. As a software testing company, we [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Codoid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codoid.softwaretestingcompany\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-29T10:05:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-04T18:59:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2021\/03\/Basic-npm-Commands-Blog.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codoid\" \/>\n<meta name=\"twitter:site\" content=\"@codoid\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Basic npm Commands - Codoid","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Basic npm Commands","og_description":"Even the smallest hiccups like package installation errors can be a bane to your productivity. In this blog article, we have listed some of the basic npm commands which are used by developers and software testers regularly to resolve package installation errors and to even upgrade existing npm packages. As a software testing company, we [&hellip;]","og_url":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2021-03-29T10:05:38+00:00","article_modified_time":"2022-02-04T18:59:22+00:00","og_image":[{"width":1200,"height":800,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2021\/03\/Basic-npm-Commands-Blog.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Basic npm Commands","datePublished":"2021-03-29T10:05:38+00:00","dateModified":"2022-02-04T18:59:22+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/"},"wordCount":695,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Automation Testing","Fixed","Blog","Latest Post"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/","url":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/","name":"Basic npm Commands - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2021-03-29T10:05:38+00:00","dateModified":"2022-02-04T18:59:22+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/learn\/automation-testing\/basic-npm-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Basic npm Commands"}]},{"@type":"WebSite","@id":"https:\/\/codoid.com\/#website","url":"https:\/\/codoid.com\/","name":"Codoid","description":"","publisher":{"@id":"https:\/\/codoid.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codoid.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codoid.com\/#organization","name":"Codoid - Software Testing Company","url":"https:\/\/codoid.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/","url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","contentUrl":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","width":500,"height":500,"caption":"Codoid - Software Testing Company"},"image":{"@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codoid.softwaretestingcompany","https:\/\/twitter.com\/codoid","https:\/\/www.instagram.com\/codoid.softwaretestingcompany\/","https:\/\/www.linkedin.com\/company\/codoid-qacompany","https:\/\/www.pinterest.com\/codoid9282\/codoid-software-testing-company\/","https:\/\/www.youtube.com\/channel\/UCCmOTDQgcf4W8oo22mBMUYA"]},{"@type":"Person","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codoid.com"]}]}},"_links":{"self":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/6907"}],"collection":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/comments?post=6907"}],"version-history":[{"count":5,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/6907\/revisions"}],"predecessor-version":[{"id":11451,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/6907\/revisions\/11451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/6910"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=6907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=6907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=6907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}