
💡NPM (Node Package Manager)
NPM is ❤️ of Javascript/Node
NPM is a javascript package manager which is basically used to install packages/modules in the project
Install NPM: NPM is installed with Node.js. So just you have to install Node.js
To install NPM packages:
npm init: It will create a package.json file.
Note
: This command should run on your root directory i.e your entry point of the project.
- package.json: The use of this file is that the packages we are installing using NPM will store in it as dependencies. It just contains the package name and its version.
Syntax: npm install <package_name>
* npm install passport
package.json
eg. {
"dependencies": {
"passport": "^0.4.0",
}
}
Note
: When we install any module 1st time using NPM, it will create a file and folder called package-lock.json(file) and node_modules(folder)
1. package-lock.json
- It contains detailed information about packages/modules which are installed in package.json as dependencies
eg. {
"passport": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/passport/-/passport-0.4.0.tgz",
"integrity": "sha1-xQlWkTR71a07XhgCOMORTRbwWBE=",
"requires": {
"passport-strategy": "1.x.x",
"pause": "0.0.1"
}
}
}
2. node_modules
: node_modules folder will contain the files. They will contain the actual code of all installed dependencies. Just you have to require these dependencies in your project and use them.
const passport = require('passport');
Done! ✌ Now only you have to install the required packages which are required for your project.