For enquiries call:

Phone

+1-469-442-0620

April flash sale-mobile

HomeBlogWeb DevelopmentWhat is NPM in Node JS?

What is NPM in Node JS?

Published
20th Sep, 2023
Views
view count loader
Read it in
5 Mins
In this article
    What is NPM in Node JS?

    If you have ever worked with Node or any JavaScript framework, then you have already worked with NPM directly or indirectly. Let’s get into the details to understand more about NPM, and learn how to install the latest versions and manage different versions using NVM. In later articles we can discuss mastering basic tools like adding, updating or removing a package. We can also touch base on some advanced features like cache, audits, scripting and more. 

    What is NPM ? 

    To build an application with JavaScript or any other frameworks like AngularReact, Express or Node.js, we rely on Package Manager to install its dependencies. This package manager is called as NPM. 

    Note: Dependencies are the packages that are used in our projects and part of the package.json. 

    NPM comes with Node.js and is pre-installed with Node. Package.json is the file containing the details of your project such as who created it, and what is the version of node and packages that your project is dependent on. 

    A package is basically a set of files combined together to serve a specific interest of function. If we visit then we can search for different packages based on the functionality we need. For example, if you search for date format to support multiple locales, we get 1171 packages (as on the date this article was written) with the topmost package being moment.  

    What is NPM in Node JS

    In short, if you are thinking of a functionality to build, then there is a high chance that there is a package already available in NPM for the same. As of January 2021, the current count is 1,493,231 packages.  

    NPM is used for building lightweight projects that can be easily shared across multiple development teams without dependencies being shared. It allows free use of resources and installs the dependencies only when needed. 

    Install npm 

    Node/npm can be installed on Mac, Windows or Linux as well. Let’s go through the steps involved in installing it on Mac. The approach should be similar for the other Operating systems. 

    For Linux, refer to this. 

    Navigate to and you will see the download sectionUnder the download, there is the other downloads link which will display different operating systems. Download the one specific to your Operating System. 

    Double click on the node-v**.**.*.pkg to install the node. It is a simple wizard with straightforward steps. 

    What is NPM in Node JS

    npm is installed with Node.js 

    If you are wondering why we are installing node instead of NPM, this is because Node.js installs NPM along with it. This is evident from the below snapshot. 

    What is NPM in Node JS

    How to check that you have node and npm installed 

    The most common way to check if node or npm is installed is by looking at the terminal. 

    Open terminal and Type in `node -v` and you should see the same version display in the installation wizard. The same applies to npm; i.e. You can type in ‘npm -v’ in terminal. 

    What is NPM in Node JS

    On Versions - A note on versionsnpm versions, Node versions and Long-Term Support 

    When we are downloading the node.js from, we have two options; i.e. LTS and Current, both pointing to different versions, and currently on the higher version. 

    What is NPM in Node JS

    LTS stands for ‘long time support and Current is the version that has the latest features, and offers support for 6 monthsAfter 6 months, odd-numbered releases will become unsupported and even numbered ones will be given LTS status with support for 30 months. 

    So, for all production applications, one should rely on Active LTS or Maintenance LTS releases. Current can be used for any trainings or by source contributors i.e. library authors.  

    What is NPM in Node JS

    Use a Node.js version manager 

    Imagine you are working on an Enterprise application for an organization which uses a specific version of Node LTSAlso imagine that there is another app (it could be your pet projectthat you are working on, for which you prefer to work on the latest version. But how can we have two different versions of Node in the same machine?  

    To achieve the same, we have NVM (Node.js version manager). Here is the official site for Mac and Linux usersWindows users can visit this link. 

    Follow the installation steps to install the NVM on your machine.  

    To verify if NVM is installed correctly, open the terminal and type in ‘nvm --version.’ 

    Type in ‘nvm list’ to display all the node.js versions that are installed on your machine. For now, you should be seeing only one version. 

    Say you want to install an outdated version of Node.js, say 12. Type in ‘nvm install 12’ in terminal and it should install the 12 version of Node.js for you.  

    Now, type in ‘nvm list’ to see both the versions of node that are available for use. 

    To switch to specific version of node, type in ‘nvm use 12’. To check if it is the active one, type in ‘node -v’. 

    Now you are good to go ahead with your project for that specific version of node.js. 

    Master the art of python competitive programming course. Unleash your coding skills and conquer challenges with Python's versatility. Join now!

    Conclusion

    NPM is one of the world's largest software registriesThe Source contributors or developers are from across the world, and use npm to share or use packages. Many organizations/firms use npm for private development as well. NPM has 3 components i.e. Website, Command Line Interface and Registry.  

    We used the website to identify the package for ‘date format’ above. We learnt to set up private packages as well alongside public. The Command Line Interface is run from the terminal and is used by most of the developers, and the Registry is the public database of the JavaScript software.  

    Profile

    Sumanth Reddy

    Author

    Full stack,UI Architect having 14+ Years of experience in web, desktop and mobile application development with strong Javascript/.Net programming skills .Strong experience in microsoft tech stack and Certified in OCI associate. Go-to-guy on integration of applications, building a mobile app by zeroing on tech stack. Majorily experienced on engineering based IIOT products and Marekting Automation products deployed on premise and on-cloud. 

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming Web Development Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon