What information is stored about every dependency in the npm file package.json?

Experience Level: Junior
Tags: npm

Answer

Dependencies in a file package.json are stored in the property dependencies.

devDependencies are stored in the property devDependencies.

The value of both of these properties is an object with multiple properties where each property name represents a dependency name and a property value represents the dependency version.

It looks like this:

{
  "name": "better-coder",
  "version": "1.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.1.2",
    "@angular/common": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/elements": "^8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/pwa": "^0.800.6",
    "@angular/router": "~8.1.2",
    "@angular/service-worker": "~8.1.2",
    "bootstrap": "^4.3.1",
    "component": "^1.1.0",
    "core-js": "^3.1.4",
    "document-register-element": "^1.14.0",
    "jquery": "^3.4.1",
    "ng2-ckeditor": "^1.2.4",
    "ngx-cookie-service": "^2.2.0",
    "ngx-webstorage-service": "^4.0.1",
    "popper.js": "^1.15.0",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.5.2",
    "tslib": "^1.10.0",
    "typescript": "^3.4.5",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.800.6",
    "@angular/cli": "^8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@types/jasmine": "^3.3.15",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.6.8",
    "browser-sync": "^2.26.7",
    "codelyzer": "~5.1.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.0",
    "ts-node": "~8.3.0",
    "tslint": "~5.17.0"
  }
}
Related npm job interview questions
npm for beginners
npm for beginners

Are you learning npm? Try our test we designed to help you progress faster.

Test yourself