The npm was originally invented by Isaac Z. Schlueter 11 years ago. Continued releases with the support of developers made a huge contribution in making npm the best version it is today.
NPM basically comes with the Node.js runtime environment and as a dependency. Many developers use Node.js with npm effectively to build apps quick and easily. Learning npm would be a big opportunity in the job industry as well.
npm mainly consists of,
- Libraries of packages (registry)
- Package Manager (cli)
The npm has its own multi-platform command line interface and it has many uses for the developer. To get npm cli we have to download and install Node.js. Click this.
The npm can be referred to this cli due to the distributed architecture of it.
The cli can be used to,
- login to npm
- initialize nodejs project (create 'package.json' file)
- run custom application based scripts (server/index.js/app.js)
npm run server
- start application
npm start app
- test your code
npm run tests
This part of npm downloads and installs the npm packages to Node.js development project when required.
First we need to initialize our app's package.json file.
npm init --y
This command makes a package.json file with default values engaged with the project's metadata. We can edit this later on ourselves. To get the initial dependencies run the installer by adding dependencies to the package.json file by adding,
You can also add the version as the value of package name.
Then we can run the command,
To automatically (without editing the package.json file first) install and edit the package.json by itself, we can use the command below.
npm i --save <package_name1> <package_name2>
Then a folder with packages named as node_modules should be installed to the location the command used in (project root directory).
After that we can use the modules.
Developers can also use developer dependencies like nodemon, karma etc. by adding
npm install -dev <dev_package_name>
We are now ready to code with the aid of newly added dependencies. By using such efficient tool we can reduce the development and reduce time by without using external plugins.
Learn more about npm with following links.