These are my notes while doing the course APIs and Microservices on https://www.freecodecamp.org. I highly recommend it if you prefer to try things directly rather than watching videos.
When starting a new project, npm generates a
package.json file. This file lists the package dependencies for your project. Since npm packages are regularly updated, the
package.json file allows you to set specific version numbers for each dependency. This ensures that updates to a package don’t break your project.
npm saves packages in a folder named
node_modules. These packages can be installed in two ways:
- globally in a root
node_modules folder, accessible by all projects.
- locally within a project’s own
node_modules folder, accessible only to that project.
package.json file is the center of any Node.js project or npm package. It stores information about your project, similar to how the <head> section of an HTML document describes the content of a webpage. It consists of a single JSON object where information is stored in key-value pairs.
"name": "fcc-learn-npm-package-json", // your project name
"author": "Max Mustermann",
"description": "A project that does something awesome",
"keywords": [ "descriptive", "related", "words", "freecodecamp" ],
"license": "MIT", // inform users of what they are allowed to do with your project
"version": "1.2.0", // describes the current version of your project
"package-name": "MAJOR.MINOR.PATCH", // Semantic Versioning
"moment": "~2.10.2" // handy library for working with time and dates.
PATCHes are bug fixes and MINORs add new features but neither of them break what worked before. Finally, MAJORs add changes that won’t work with earlier versions. Find a more detailed explanation here.
To allow an npm dependency to update to the latest PATCH version, you can prefix the dependency’s version with the tilde (
The caret (
^) will allow both MINOR updates and PATCHes.