npm

npm vs bower

npm is most commonly used for managing Node.js modules, Bower is created solely for the front-end and is optimized with that in mind. The biggest difference is that npm does nested dependency tree (size heavy) while Bower requires a flat dependency tree. use npm for developer tools like Yeoman, Grunt, Gulp, JSHint, CoffeeScript, etc. In large projects the way to specify dependencies is by creating a file called package.json which contains a list of dependencies.

JavaScript community shares hundreds of thousands of pieces of code so we can avoid rewriting . Each piece of code may in turn depend on other pieces of code, and these dependencies are managed by package managers. The most popular JavaScript package manager is the npm client, which provides access to more than 300,000 packages in the npm registry.

install

npm is included in the Node.js installation. npm --version (or npm -v )

however, npm gets updated more frequently than Node does, so you'll update it to the latest version. sudo npm install npm -g

proxy

In order to authenticate with the corporate proxy while using tools such as NPM, we could pass our credentials on the URI of the proxy, there's another option - CNTLM. If you have previously configured the npm with 'proxy' and 'https-proxy' options, you should clear them so that your environment variables will be used. npm config delete proxy npm config delete https-proxy

only if npm is ignoring your environment variables , do this npm config set proxy http://localhost:3128

usage
  1. create a directory to hold your application, and make that your working directory.

    $ mkdir myapp
    $ cd myapp
    
  2. use the npm init command to create a package.json file for your application.

    $ npm init
    

    This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception: entry point: (index.js) Enter app.js

  3. Set NPM Registry: Some dependencies reside in an internal registry. Configure NPM's registry:

    e.g.
    npm set registry=https://repo.abc.aws.com/npm/
    
  4. now install Express in the myapp directory and save it in the dependencies list. For example:

    $ npm install express --save
    To install Express temporarily and not add it to the dependencies list:
    $ npm install express --no-save
    [By default with version npm 5.0+ 'npm install' adds the module to the dependencies list in the package.json file; with earlier versions of npm, you must specify the --save option explicitly. Then, afterwards, running 'npm install' in the app directory will automatically install modules in the dependencies list.]
    
  5. This gives us information about our install: npm config list

npm can install packages in local or global mode.

get the current global location: $ npm config get prefix C:\Users\n0264102\AppData\Roaming\npm to change the location of the global Node packages $ npm config set prefix=$HOME/.node_modules_global

to install UglifyJS globally using the --global flag, can be abbreviated to -g. $ npm install uglify-js --global

to list the global packages we have installed npm list --global

  1. When npm installs a package it keeps a copy, so the next time you want to install that package, it doesn’t need to hit the network. The copies are cached in the .npm directory in your home path. It’s useful to clean it up occasionally.
    $ rmdir /s node_modules
    $ npm cache clean
    $ npm install -dd
    
    In local mode it installs the package in a node_modules folder.

results matching ""

    No results matching ""