1. Explain what “npm
” stands for.
2. Explain the purpose of the package.json file and node_modules directory.
npm install
3. Given multiple choices, identify the difference between npm’s package.json and package-lock.json files. | package.json
| package-lock.json
| | ———— | —————– | | Contains meta-data, scripts & dependencies | Contains details about installed dependencies | | Dependencies are requests | Represent an exact reproducible npm environment | | Safe to edit, just be careful about syntax | Do not edit this at all!| | Should be manually edited| Always contains exact version of each package| | Is auto created when you run npm.init | Auto created when npm install is run| | May contain a range of acceptable versions| |
4. Use npm –version to check what version is currently installed and use npm to update itself to the latest version.
npm --version
// checks current version.npm install -g npm@latest
// use this to update the package to the latest version.5. Use npm init to create a new package and npm install to add a package as a dependency. Then use require to import the module and utilize it in a JavaScript file.
npm init --yes
to create a new packagenpm install lodash
to install a package.6. Given a package version number following the MAJOR.MINOR.PATCH semantic versioning spec that may include tilde (~) and caret (^) ranges, identify the range of versions of the package that will be compatible.
Asterisk // Searches for all versions, also indicates latest version.
14.16.1 // Finds exact version.
~14.16.1 // Finds everything with same Major and Minor Range.
^14.16.1 // Finds everything greater than current search.
|| // Can use to find multiple ranges.
7. Explain the difference between a dependency and a development dependency.
8. Given an existing GitHub repository, clone the repo and use npm to install it’s dependencies.
9. Use npm uninstall to remove a dependency.
10. Use npm update to update an out-of-date dependency.
11. Given a problem description, use the npm registry to find a reputable package (by popularity and quality stats) that provides functionality to solve that problem.
12. Given a package with vulnerabilities due to outdated dependency versions, use npm audit to scan and fix any vulnerabilities.
npm audit
to get an auditnpm audit fix
to fix low level, safe errors.npm audit fix --force
to force correct errors - might break your code.13. Write and run an npm script.
npm run linecount