{ "version": "0.4.2", "summary": { "title": "Learn NPM package json", "description": "The Node Package Manager (NPM) is a command-line tool used by developers to share and control modules (or packages) of JavaScript code written for use with Node.js." }, "config": { "testRunner": { "command": "npm run test --", "args": { "filter": "--grep", "tap": "--reporter=mocha-tap-reporter" }, "directory": "coderoad" }, "setup": { "commands": [ "cd coderoad && npm install" ], "commits": [ "6bfa2e3f1d8e9e3dcb07ab7c6b8bc863f56e11b0" ] }, "repo": { "uri": "https://github.com/coderoad/fcc-learn-npm", "branch": "v0.4.2" }, "dependencies": [ { "name": "node", "version": ">=10" } ], "reset": { "commands": [ "echo 'resetting'" ] } }, "levels": [ { "id": "1", "title": "Intro", "summary": "Introduction to the package.json", "content": "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.\n\nNPM saves packages in a folder named node_modules. These packages can be installed in two ways:\n\n- globally in a root node_modules folder, accessible by all projects.\n- locally within a project's own node_modules folder, accessible only to that project.\n\nMost developers prefer to install packages local to each project to create a separation between the dependencies of different projects.\n\nThe `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. There are only two required fields; \"name\" and \"version\", but it’s good practice to provide additional information about your project that could be useful to future users or maintainers.\nIf you look at the file tree of your project, you will find the package.json file on the top level of the tree. This is the file that you will be improving in the next couple of challenges.", "steps": [] }, { "id": "2", "title": "Author", "summary": "Package.json author", "content": "One of the most common pieces of information in this file is the `author` field. It specifies who created the project, and can consist of a string or an object with contact or other details. An object is recommended for bigger projects, but a simple string like the following example will do for this project.\n\n```json\n\"author\": \"Jane Doe\",\n```", "steps": [ { "id": "2.1", "setup": { "commands": [ "npm install" ], "files": [ "package.json" ], "commits": [ "ae28b98a44066947fa2a3ecab26e62e0743ff016" ] }, "solution": { "files": [ "package.json" ], "commits": [ "e2778eaea801474be3569e31941651b11da08601" ] }, "content": "Add your name as the `author` of the project in the package.json file.\n**Note:** Remember that you’re writing JSON, so all field names must use double-quotes (\") and be separated with a comma (,).", "hints": [ "Edit the file `package.json`", "Add a property of \"author\" to the object" ] } ] }, { "id": "3", "title": "Description", "summary": "Package.json description", "content": "The next part of a good package.json file is the `description` field; where a short, but informative description about your project belongs.\nIf you some day plan to publish a package to NPM, this is the string that should sell your idea to the user when they decide whether to install your package or not. However, that’s not the only use case for the description, it’s a great way to summarize what a project does. It’s just as important in any Node.js project to help other developers, future maintainers or even your future self understand the project quickly.\n\nRegardless of what you plan for your project, a description is definitely recommended.\n\nHere's an example:\n\n```json\n\"description\": \"A project that does something awesome\",\n```", "steps": [ { "id": "3.1", "setup": { "files": [ "package.json" ], "commits": [ "c2f35a0e0c1d88435e7cb87d61d2a23b011d231b" ] }, "solution": { "files": [ "package.json" ], "commits": [ "dbbdf52595dcfe9d39343f0b8a2ebb6cc7254c1e" ] }, "content": "Add a `description` to the package.json file of your project.\n\n**Note:** Remember to use double-quotes for field-names (\") and commas (,) to separate fields.", "hints": [ "Edit the file `package.json`", "Add a property of \"description\" to the object" ] } ] }, { "id": "4", "title": "Keywords", "summary": "Package.json keywords", "content": "The `keywords` field is where you can describe your project using related keywords.\n\nHere's an example:\n\n```json\n\"keywords\": [ \"descriptive\", \"related\", \"words\" ],\n```\n\nAs you can see, this field is structured as an array of double-quoted strings.", "steps": [ { "id": "4.1", "setup": { "files": [ "package.json" ], "commits": [ "9cfe1fec533df98eb9c6ed927eac8e0103ecdd50" ] }, "solution": { "files": [ "package.json" ], "commits": [ "7212e9079d67470e0ea6f21906b308ee82ba483d" ] }, "content": "Add an array of suitable strings to the `keywords` field in the package.json file of your project.\n\nOne of the keywords should be \"freecodecamp\".", "hints": [ "Edit the file `package.json`", "\"keywords\" should be an array including the string \"freecodecamp\"" ] } ] }, { "id": "5", "title": "License", "summary": "Package.json license", "content": "The `license` field is where you inform users of what they are allowed to do with your project.\n\nSome common licenses for open source projects include MIT and BSD. License information is not required, and copyright laws in most countries will give you ownership of what you create by default. However, it’s always a good practice to explicitly state what users can and can’t do. Here's an example of the license field:\n\n```json\n\"license\": \"MIT\",\n```", "steps": [ { "id": "5.1", "setup": { "files": [ "package.json" ], "commits": [ "9652bd6438d1f403fdef12580616ed99771b3a3b" ] }, "content": "Fill the `license` field in the package.json file of your project as you find suitable.", "solution": { "commits": [ "effa4b7d6e65428affaff4423832b39a4314b161" ] } } ] }, { "id": "6", "title": "Version", "summary": "Package.json version", "content": "A `version` is one of the required fields of your package.json file. This field describes the current version of your project. Here's an example:\n\n```json\n\"version\": \"1.2.0\",\n```", "steps": [ { "id": "6.1", "setup": { "files": [ "package.json" ], "commits": [ "dfbce6652999bf559aed44434cec24c80e494452" ] }, "content": "Add a `version` to the package.json file of your project.", "solution": { "commits": [ "784e624939e8e47283ae9e687d2fc4fb5fcfcd61" ] } } ] }, { "id": "7", "title": "External Packages", "summary": "Installing dependencies from NPM", "content": "One of the biggest reasons to use a package manager, is their powerful dependency management. Instead of manually having to make sure that you get all dependencies whenever you set up a project on a new computer, NPM automatically installs everything for you. But how can NPM know exactly what your project needs? Meet the `dependencies` section of your package.json file.\n\nIn this section, packages your project requires are stored using the following format:\n\n```json\n\"dependencies\": {\n \"package-name\": \"version\",\n \"express\": \"4.17.0\"\n}\n```\n\nInstall a package by running the NPM command line tool in a terminal with the command `install`.\n\n```shell\nnpm install express\n```\n\n**Note:** Use the Use the `⌃\\`` keyboard shortcut with the backtick character to open the VSCode integrated terminal.\n\nInstalled packages are created in a `node_modules` folder in your project. Avoid editing or changing the node_modules folder or its contents.", "steps": [ { "id": "7.1", "setup": { "files": [ "package.json" ], "watchers": [ "package.json", "node_modules/moment" ], "commits": [ "327be97be42414034279727046ced58130ebbeee" ] }, "solution": { "files": [ "package.json" ], "commands": [ "npm install" ], "commits": [ "0eefcdbb090e62515c19b41d51998fe18bfcb7ac" ] }, "content": "Install the \"moment\" package to the `dependencies` field of your package.json file by running the command line npm install.\n\n**Note:** Moment is a handy library for working with time and dates." } ] }, { "id": "8", "title": "Semantic Versioning", "summary": "Versioning packages", "content": "`Versions` of the npm packages in the dependencies section of your package.json file follow what’s called Semantic Versioning (SemVer), an industry standard for software versioning aiming to make it easier to manage dependencies. Libraries, frameworks or other tools published on npm should use SemVer in order to clearly communicate what kind of changes projects can expect if they update.\n\nKnowing SemVer can be useful when you develop software that uses external dependencies (which you almost always do). One day, your understanding of these numbers will save you from accidentally introducing breaking changes to your project without understanding why things that worked yesterday suddenly don’t work today. This is how Semantic Versioning works according to the official website:\n\n```json\n\"package\": \"MAJOR.MINOR.PATCH\"\n```\n\nThe MAJOR version should increment when you make incompatible API changes.\n\nThe MINOR version should increment when you add functionality in a backwards-compatible manner.\n\nThe PATCH version should increment when you make backwards-compatible bug fixes.\nThis means that 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.\n\nUsing the NPM cli, a specific version of a package can be installed by specifying the `@` version.\n\n```shell\nnpm install express@4.17.0\n```", "steps": [ { "id": "8.1", "setup": { "files": [ "package.json" ], "watchers": [ "package.json", "node_modules/moment" ], "commits": [ "e25b5f37da2f052080f29bc0f1e6fb6b3ba43d93" ] }, "solution": { "files": [ "package.json" ], "commands": [ "npm install" ], "commits": [ "ec1e905af4139e524369974dadcbec6a08343fcd" ] }, "content": "In the dependencies section of your package.json file, change the `version` of moment to match MAJOR version 2, MINOR version 10 and PATCH version 2" } ] }, { "id": "9", "title": "Receive Patch Updates", "summary": "Using `~` to recieve patches", "content": "In the last challenge, you told npm to only include a specific version of a package. That’s a useful way to freeze your dependencies if you need to make sure that different parts of your project stay compatible with each other. But in most use cases, you don’t want to miss bug fixes since they often include important security patches and (hopefully) don’t break things in doing so.\n\nTo allow an npm dependency to update to the latest PATCH version, you can prefix the dependency’s version with the tilde (`~`) character. Here's an example of how to allow updates to any 1.3.x version.\n\n```json\n\"package\": \"~1.3.8\"\n```", "steps": [ { "id": "9.1", "setup": { "files": [ "package.json" ], "commits": [ "c7fecf0bce6abe2885b6d968486ad22417a6eded" ] }, "solution": { "files": [ "package.json" ], "commits": [ "70b29effbc6a65e1cab618edd92879949160a1a0" ] }, "content": "In the package.json file, your current rule for how npm may upgrade moment is to use a specific version (2.10.2). But now, you want to allow the latest 2.10.x version.\nUse the tilde (`~`) character to prefix the version of moment in your dependencies, and allow npm to update it to any new PATCH release.\n\n**Note:** The version numbers themselves should not be changed." } ] }, { "id": "10", "title": "Receive Minor Updates", "summary": "Using `^` to receive minor updates", "content": "Similar to how the tilde we learned about in the last challenge allows npm to install the latest PATCH for a dependency, the caret (`^`) allows npm to install future updates as well. The difference is that the caret will allow both MINOR updates and PATCHes.\n\nYour current version of moment should be \"~2.10.2\" which allows npm to install to the latest 2.10.x version. If you were to use the caret (`^`) as a version prefix instead, npm would be allowed to update to any 2.x.x version.\n\n```json\n\"package\": \"^1.3.8\"\n```\n\nThis would allow updates to any 1.x.x version of the package.", "steps": [ { "id": "10.1", "setup": { "files": [ "package.json" ], "commits": [ "dc2689e47dcb0db5933ce8d599bbd292b08b9bda" ] }, "solution": { "files": [ "package.json" ], "commits": [ "72b8fa6680bf55da451b92ccdda89974b6742617" ] }, "content": "Use the caret (`^`) to prefix the version of moment in your dependencies and allow npm to update it to any new MINOR release.\n\n**Note:** The version numbers themselves should not be changed." } ] }, { "id": "11", "title": "Remove a Dependency", "summary": "Removing a dependency", "content": "You have now tested a few ways you can manage dependencies of your project by using the package.json's dependencies section. You have also included external packages by adding them to the file and even told npm what types of versions you want, by using special characters such as the tilde or the caret.\n\nBut what if you want to remove an external package that you no longer need? You might already have guessed it, just remove the corresponding key-value pair for that package from your dependencies.\n\nThis same method applies to removing other fields in your package.json as well.", "steps": [ { "id": "11.1", "setup": { "files": [ "package.json" ], "commits": [ "6b0d618d312d7db46a5c30062a7ea1730ee2992c" ] }, "solution": { "files": [ "package.json" ], "commits": [ "41e46747dfb3977c21321d473b5f230e91240d4f" ] }, "content": "Remove the moment package from your dependencies.\n\n**Note:** Make sure you have the right amount of commas after removing it." } ] } ] }