Code Road

Visualization of a Code Road tutorial
Click to see more info
Learn NPM Repo
master
v0.1.0
Project Files
CODEROAD.md
config.json
Tutorials Repo
CodeRoad Repo
# Learn NPM package json
> 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 config: testRunner: command: npm run programmatic-test repo: uri: https://github.com/coderoad/fcc-learn-npm branch: v0.1.0 dependencies: - name: node version: ^10 ```
## Intro
> Introduction to the package.json
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. Most developers prefer to install packages local to each project to create a separation between the dependencies of different projects. The `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. If 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.
## Author
> Package.json author
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. ```json "author": "Jane Doe", ```
### Step 1 ```config setup: files: - package.json commits:
- '26e502d'
- 'e39ab72'
commands: - npm install solution: files: - package.json commits:
- '72fa9de'
```
Add your name as the `author` of the project in the package.json file.
**Note:** Remember that you’re writing JSON, so all field names must use double-quotes (") and be separated with a comma (,).
## Description
> Package.json description
The next part of a good package.json file is the `description` field; where a short, but informative description about your project belongs. If 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. Regardless of what you plan for your project, a description is definitely recommended. Here's an example: ```json "description": "A project that does something awesome", ```
### Step 1 ```config setup: files: - package.json commits:
- '64bd78f'
solution: files: - package.json commits:
- '7888392'
```
Add a `description` to the package.json file of your project.
**Note:** Remember to use double-quotes for field-names (") and commas (,) to separate fields.
## Keywords
> Package.json keywords
The `keywords` field is where you can describe your project using related keywords. Here's an example: ```json "keywords": [ "descriptive", "related", "words" ], ``` As you can see, this field is structured as an array of double-quoted strings.
### Step 1 ```config setup: files: - package.json commits:
- '54540f6'
solution: files: - package.json commits:
- '803ab94'
```
Add an array of suitable strings to the `keywords` field in the package.json file of your project.
One of the keywords should be "freecodecamp".
x