nodejslearnerfiles
Version:
Very Good Beginnings if you want to Learn Node.js
113 lines (84 loc) • 3.57 kB
JavaScript
/*
What is the difference between a Package and a Module ?
A module is a single javascript file that has some re-usable functionality.
A package is a directory with one or more modules inside it. and a package.json file which has metadata about the package.
Each and every package has a package.json file and other files.
essentially, npm will help you deal/manage these packages. hence the name, node package manager.
Download a node project, using git clone. You will do the following :-
npm install
npm start ( to check if the node project has a start script, open the package.json file)
You should see something like this :-
"scripts:" {
"start": "node server.js"
"test": "node test.js"
}
##Help with NPM
npm -h
npm install -h
npm help install
npm help-search remove (all commands that are related to remove)
there are npm shortcuts too
## Types of Projects
- For Users
- For Other developers (3rd Party Packages)
## Reasons for Package.json files
- Track dependencies.
- Create Scripts.
## To create a module, first you should start with creating a package.json file.
- issue "npm init" (asks you questions, with default answers.)
- issue "npm init -y" (to create package.json by accepting the defaults)
- npm set init-author-name "Sai M" (npm get init-author-name)
- npm set init-license "MIT" (npm get init-license)
- npm config delete init-author-name (to delete the setting)
When installing other packages, and to have them as your dependencies, include a --save flag.
- npm install express --save
- npm install loadash -S (same as above) or npm i loadash -S
To save it in the DevDependencies.
- npm install karma -save--dev or npm install karma -D
Listing installed packages inside the project.
- ls node_modules/
or
npm list or
npm list --depth 1 or
npm list --depth 0 (Just to get the list of packages that have been installed.)
npm list --global (list of packages installed globally)
npm list --global --depth 0
npm list --depth 0 --long true (Gives a whole lot of information about the packages, installed at the global level
at a depth of 0)
To print it in json format.
npm list --depth 0 --json true
or in parsable format.
npm list --depth 0 --parsable true
or
npm list --depth 0 --dev true (development dependencies)
Removing the packages.
npm uninstall underscore --save (to remove it from your package.json file.)
Semantic Version
underscore@1.8.4
Major Version - In the case when you break the functionality and do something thats no longer backward compatible. this is the time When
you updte Major Version number. (2.0.0)
Minor Version - If new features are involved. (1.9.0) - new functionality is added.
Revision or Patch Number - only incremented when a bug is fixed or performance improvement, it doesn't change the functionality.
Install a specific version of node package.
npm install underscore@1.8.3
or
Install a most recent patch of 1.8
npm install underscore@1.8.x
Or you can get more complex with > and < signs.
npm install underscore@">=1.1.0 <1.4.5"
"underscore":"^1.8.3" (if a new patch is released, npm will update it.)
If you don't want to get it updated.
then
npm install underscore@1.8.3 --save --save-exact
"underscore":"1.8.3" ( you don't want to upgrade automatically )
so, "^" means, the latest version of the Major release.
"~" means, the latest version of the minor release.
"x" means, you get the latest.
"1.8.1" means, install specific version.
npm update
npm update --dev
npm update --prod
//
npm update underscore (Just one dependency at a time.)
npm update g (updating global deps)
*/