1.

How To Use Npm?

Answer»

There are 2 ways to install a package using NPM: globally and locally.

  • Globally: This method is generally USED to install development tools and CLI based packages. To install a package globally, use:
    $ npm install -G <package-name>
  • Locally: This method is generally used to install frameworks and libraries. A locally installed package can be used only within the directory it is installed. To install a package locally use the same command as above without the -g flag.
    $ npm install <package-name>

Whenever we create a project using npm, we need to provide a package.json file, which has all the DETAILS about our project. npm make it easy for us to set up this file. Let us set up our development project.

  1. Fire up your terminal/cmd, create a new folder named hello-world and cd into it: npm into it
  2. Now to create the package.json file using npm, use the following.--npm init
  3. Now we have our package.json file set up, we’ll install koa. To install koa and add it in our package.json file, we use the following command:
    $ npm install --save koa

    To confirm koa installed correctly, run

    $ ls node_modules #(dir node_modules for windows)

There are 2 ways to install a package using npm: globally and locally.

Whenever we create a project using npm, we need to provide a package.json file, which has all the details about our project. npm make it easy for us to set up this file. Let us set up our development project.



Discussion

No Comment Found