NPM Module #43 Flashcards
How would you install a package?
npm install package-name
How would you make sure dependencies are added to the package.json file?
npm install package-name –save OR
npm install package-name –save-dev which adds the package to package.json devDependencies
*Both are important for compiling a bunch of things later
The difference is mainly that devDependencies are usually development tools, like a testing library, while dependencies are bundled with the app in production.
What’s another perhaps quicker way of adding devDependencies to package.json?
Simply type the -D flag instead of –save-dev
Without deliberately specifying production, NPM assumes a dev build. How would you avoid this if you were intalling into production?
By setting the —production flag.
How would you globally install a package and why would you want to do that vs. a local project?
Use the -g flag
Typically this is for other command line tools. A package should be installed globally when it provides an executable command that you run from the shell (CLI), and it’s reused across projects. vue/cli wordpress cli etc
What are the rules for NPM versioning?
The Semantic Versioning concept is simple: all versions have 3 digits: x.y.z.
the first digit is the major version the second digit is the minor version the third digit is the patch version
How can you return a list of global dependencies?
npm list -g –depth 0
What are the various ways to uninstall a package?
Using the -S flag, or –save, this operation will also remove the reference in the package.json file.
If the package was a development dependency, listed in the devDependencies of the package.json file, you must use the -D / –save-dev flag to remove it from the file:
npm uninstall -S
npm uninstall -D
If the package is installed globally, you need to add the -g / –global flag:
npm uninstall -g `
What is stored in the package.json file?
It’s a central repository of configuration for tools, for example. It’s also where npm store the names and versions of the package it installed. The list is below.
The file structure
Properties breakdown
name author contributors bugs homepage version license keywords description repository main private scripts dependencies devDependencies engines browserslist Command-specific properties
What are the constraints and rules for setting the name in a package.json file?
The name must be less than 214 characters, must not have spaces, it can only contain lowercase letters, hyphens (-) or underscores (_).
How would you structure the GIT information in the package.json?
“repository”: “github:flaviocopes/testing”,
or you can explicitly set the version control system:
“repository”: {
“type”: “git”,
“url”: “https://github.com/flaviocopes/testing.git”
}
If privacy is set to “false” in package.json, what happens?
The package is published to NPM. Make sure that it is set to “true” unless you intend to publish.
What is the command to install devDependencies? Why is this different from dependencies?
stall –only=dev
This inserts the dependencies required for development, not the final production build.
What is the package-lock.json file?
The goal of the file is to keep track of the exact version of every package that is installed so that a product is 100% reproducible in the same way even if packages are updated by their maintainers.
The package-lock.json sets your currently installed version of each package in stone, and npm will use those exact versions when running npm install.
How can you make updates to globally installed packages?
npm install -g npm-check-updates
Then run ncu -u
This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.