Fraser Hamilton

A guide to package.json

June 30, 2020

If you’re operating in the JavaScript ecosystem you’re certain to come across the package.json file. It’s primarily used to identify the project on npm and manage the projects dependencies. However due to it’s placement at the heart of almost any JavaScript project it’s also often used for the configuration of various modules and tools.

Properties

name

Sets the module name

"name": "test-module"

There’s some restrictions on this field, it must be less than 214 characters, no uppercase letters and no spaces. You can use hyphens and underscores though.

version

Denotes current version of the module

"version": "1.12.4"

license

Indicates the license of the module

"license": "MIT"

description

Contains a brief description of the module

"description": "Parse, validate, manipulate, and display dates"

author

Lists the module authors name

"author": {
    "name": "Fraser Hamilton",
    "email": "fraser@webuilddigital.com",
    "url": "https://fraserhamilton.dev"
}

contributors

Lists people who have contributed

 "contributors": [
    "Your Friend <friend@example.com> (http://friends-website.com)",
    "Other Friend <other@example.com> (http://other-website.com)"
  ]

keywords

Contains a collection of keywords relating to the module

"keywords": [
    "date",
    "time",
    "parse",
    "format",
    "validate",
]

main

The entry point to the module

"main": "index.js",

repository

Defines where the source code lives

"repository": {
    "type": "git",
    "url": "https://github.com/moment/moment.git"
}

homepage

The URL to the landing page or documentation for your module

"homepage": "https://momentjs.com"

bugs

The URL to your project’s issue tracker

"bugs": "https://github.com/moment/moment/issues"

scripts

Defines a set of scripts you can run

"scripts": {
    "start": "nodemon ./index.js",
    "build": "rollup --config",
    "test": "jest",
},

dependencies

Indicates your modules dependencies as well as their versions

"dependencies": {
    "nodemon": "latest",
    "lodash": "^4.17.15",
    "split": "0.3.0",
  },

devDependencies

Indicates your modules development dependencies as well as their versions

"devDependencies": {
    "prettier": "latest",
    "jest": "26.1.0",
    "rollup": "^2.18.0",
  },


Written by Fraser Hamilton a full stack developer based out of Edinburgh, Scotland.

© 2020, Fraser Hamilton