#Node - NPM Basics
NPM is the Node Package Manager. It is used to install, update and uninstall modules. It will also recursively install dependencies of the installed module. Modules normally reside in the node_modules folder.
###Important Security Note
Node comes with the npm package manager. It is strongly encouraged that you should not to do package management with sudo
. Packages can run arbitrary scripts which makes them a potential security risk.
It is recommended that you give your user account access to the /usr/local folder instead:
sudo chown -R $USER /usr/local
That sets your user account as the owner of the /usr/local directory
, so that you can just issue normal commands in there. Then you won’t ever have to use sudo
when you install node or issue npm
commands.
###Find Available Packages
Find Available Packages
http://npmjs.org
Search for Available Packages
http://search.npmjs.org
npm search mp3
To view the details
npm view express
Show all Installed Packages
npm list
###Installing Modules
Installing Latest Module
npm install <package>
npm install marked
Installing Latest Module Globally
npm install -g <package>
npm install -g marked
Install Specific Module Version
npm install <package>@<version spec>
npm install marked@0.2.6
Install Specific Module Version Range
npm install <package>@<partial version spec>.x
npm install marked@0.2.x
###Uninstalling a Module
npm uninstall <package>
npm uninstall marked
Uninstalling Globally
npm uninstall -g <package>
npm uninstall -g marked
###Updating a Module
Updating an Installed Module
npm update <package>
npm update marked
Updating a Globally Installed Module
npm update -g <package>
npm update -g marked
##package.json
{
"name" : "MyApp",
"version" : "1.0.0",
"dependencies" : {
"marked" : "2.6.0",
"request" : ">0.2.0"
}
}
Install package.json Dependencies
npm install -d
###Options
npm help json
Update global settings
npm set global=true
npm get global
To find all the folders npm uses
npm help folders
npm uninstall express
npm outdated
npm updated express
###Private Packages If you do not want to publish the project then use:
"private": "true"