So we installed NodeJS on our machine.
Because there is already a lot of code out there in the internet, we can use other peoples’ code so we do not have to reinvent the wheel to solve problems, that are already solved.
In order to easily get solutions from other people, we can use a tool called npm.
This will be a short intro to npm with the most used commands. If you want to learn some advanced concepts, read the npm documentation.
- npm is the world’s largest software registry
- npm comes with the NodeJS installer, so if you already installed NodeJS, you already have npm on your machine
- you download packages with the command line interface
- you get information about packages through the npm website
If you already installed NodeJS, you already have npm on your machine.
To check, if npm is installed:
Most of the time, you want to use packages project-wise.
- Initialize a npm project in an existing folder:
npm init. This will create a
package.jsonfile, where all your settings will be saved.
- Answer all questions like
versionetc. You can read about the correct answers here
- Go to npm and search for a package, e.g. “text color”.
- You will get a list of matching packages, click on the link to the package and read the documentation, e.g. the package “chalk”.
- Most of the time, the documentation will give you an appropriate command to install the package, e.g.
npm install chalk. If you want to see all the possibilities how to
npm installa package, read the npm install docs.
- The package gets downloaded, you have to wait for some time.
- Read the package documentation to learn how to use the package.
If you want to learn additional commands, e.g. uninstall a package, read the documentation
- What beginner’s problem would you have liked to have solved here as well?
- Are the instructions clear, understandable and comprehensible?