npm Flashcards
- What is NPM?
a. Trick question – you should ask… what part of the npm?
b. NPM is the world’s largest software registry. It consists of three distinct components:
i. The website
1. The website is used to discover packages, set up profiles, and manage other aspects of your npm experience.
ii. The Command Line Interface (CLI)
1. The CLI runs from a terminal, and is how most developers interact with npm.
iii. The registry
1. The registry is a large public database of JavaScript software and the meta-information surrounding it.
- What is a package?
a. A directory with one or more files PLUS a package.json file – Tim.
b. A package.json file
i. lists the packages your project depends on
ii. specifies versions of a package that your project can use using semantic versioning rules
iii. makes your build reproducible, and therefore easier to share with other developers
- How can you create a package.json with npm?
a. To create a package.json file with values that you supply, use the npm init command.
i. On the command line, navigate to the root directory of your package.
1. cd /path/to/package
ii. Run the following command.
1. npm init
iii. Answer the questions in the command line questionnaire.
iv. To create a default package.json file
1. On the command line, navigate to the root directory of the package.
a. cd /path/to/package
2. Run the following command:
a. npm init – yes
- What is a dependency and how to you add one to a package?
a. A third party code that your project relies on to function properly - Tim
- What happens when you add a dependency to a package with npm?
a. It downloads the package from the registry, installs the dependencies into the nod_modules folder and updates package.json to list that package dependency.
b. When you (or another user) run npm install , npm will download dependencies and devDependencies that are listed in package. json that meet the semantic version requirements listed for each.
c. For more information on semantic version requirements https://semver.org/