npm Flashcards
What is NPM?
software registry of packages
a command line interface
aka “The public npm registry is a database of JavaScript packages, each comprised of software and metadata. “
What is a package?
“The npm registry contains packages, many of which are also Node modules, or contain Node modules.”
aka
“A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.”
aka
“Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public.”
How can you create a package.json with npm?
“You can create a package.json file by running a CLI questionnaire or creating a default package.json file”
“A package.json file:
- lists the packages your project depends on
- specifies versions of a package that your project can use using semantic versioning rules
- makes your build reproducible, and therefore easier to share with other developers”
What is a dependency and how do you add one to a package?
- dependencies: packages required by your application in production
- devDependencies: packages that are only needed for local development and testing
You can add dependencies to a package.json file from the command line or by manually editing the package.json file.
i.e.,
for production (see 1.) npm install [--save-prod]
for local development/testing (see 2.)
npm install –save-dev
What happens when you add a dependency to a package with npm?
your package.json file gets altered i.e., the dependency is added into to the “dependencies” attribute in your package.json file
creates a node_modules folder with the dependencies