Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Node Package Manager in Node.js

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 318
    Comment on it

    Node Package Manager (npm) stands for node package manager and it is a command line interface for installing Node.js packages,do version management and dependency management of Node.js packages.
    npm can be used to install packages in local or global mode. If we install the package in the local mode it will install it in a node_modules folder in our working directory.

    By using npm we can share the code, reuse the code and update the code.

    Install npm:
    npm comes bundled with Node.js. So first of all install NodeJS.

    Before installing node js we need to run following command, as this will updates the local repository information.
       

     sudo apt-get update


    Install the Node.js package using following command.
       

     sudo apt-get install nodejs


    Install Node Package manager
     

     sudo apt-get install npm


    If you have already installed npm check the version by the below command:
     

    npm --version

    In order to update an old version of npm run the following command.
     

    sudo npm install npm -g

    To install any Node.js module using npm:

    npm install "Module_name"


    By default, npm installs any dependency in the local mode i.e in node_modules directory. And these packages are accessible via require() method.
    Now suppose we have a js file in which we want to use Node.js web framework module express. So in order to install express module, we will use npm.
     

    npm install express

    After installing express mode we can use this module in our js file as following:

    var express = require('express');

    To install express module globally
     

    npm install express -g

    Note that Globally installed packages were stored in system directory and can not be imported using require() in Node application.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: