How to Install a Specific Package using npm via Command Line

Posted on

This article will show how to install a specific package using ‘npm’ tool. First of all, the tool must be available in the operating system. Since it is a command exist in the command line, just type the ‘npm’ command to test it. If the command is not available, install the ‘npm’ tool command before installing an additional package. The additional package installation has a specific pattern and additional argument or parameter. In order to look and to compare the differentiation of the command pattern, take a look in this link. That is an article where the main focus is to install any available packages. But in this article, the main focus is to be able to install just a specific package name. It can be done by adding another additional parameter or argument. Just take a look to both of the commands below :

The following is the simple installation command using ‘npm’ :

npm i

Another version of the above command pattern is :

npm install

Another command pattern exist as follows :

npm i -S package_name

For an example :

npm i -S test_search_package
user@hostname:~/express/myapp$ npm i -S test_search_package
npm WARN npm npm does not support Node.js v10.15.2
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! code E404
npm ERR! 404 Not Found: test_search_package@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2020-03-18T07_02_56_619Z-debug.log
user@hostname:~/express/myapp$ 

As in the above output, there is an additional argument and package name specified after ‘-S’. It is the name of the package which is going to be installed. Apparently, there is no package name with the name of ‘test_search_package’. The case will be totally different if there is a package with the name of that. The process will go through for the installation of that package. It exist as the following example :

user@hostname:~/riset/express/myapp$ npm i -S serve-favicon
npm WARN npm npm does not support Node.js v10.15.2
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm notice created a lockfile as package-lock.json. You should commit this file.
+ serve-favicon@2.5.0
added 6 packages from 5 contributors in 1.535s
user@hostname:~/express/myapp$

As expected in the above output, since there is a package with the name of ‘serve-favicon’, the installation process of the package with the name of ‘serve-favicon’ continue on.

One thought on “How to Install a Specific Package using npm via Command Line

Leave a Reply