What is package.json file?

0

What is package.json?

what is package.json?


A package.json file contains metadata about the app and it also includes the list of dependencies to be installed using npm. It must be actual JSON, not just a JavaScript object literal.

name

The most important things in your package.json are the name and version fields. Those are actually required, and your package won’t install without them. The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version.

version

The most important things in your package.json are the name and version fields. Those are actually required, and your package won’t install without them. The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version.

description

Put a description in it. It’s a string. This helps people discover your package, as it’s listed in npm search

keywords

Put keywords in it. It’s an array of strings. This helps people discover your package as it’s listed in npm search.

homepage

The URL to the project homepage.

bugs

The URL to your project’s issue tracker and/or the email address to which issues should be reported. These are helpful for people who encounter issues with your package. It should look like this:

{ "url" : "https://github.com/owner/project/issues", "email" : "project@hostname.com" }
You can specify either one or both values. If you want to provide only a URL, you can specify the value for “bugs” as a simple string instead of an object.
If a URL is provided, it will be used by the npm bug command.

license

You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you’re placing on it.
If you’re using a common license such as BSD-2-Clause or MIT, add a current SPDX license identifier for the license you’re using, like this:

{ "license" : "BSD-3-Clause" }
people fields: author, contributors
The “author” is one person. “contributors” is an array of people. A “person” is an object with a “name” field and optionally “url” and “email”, like this:

{ "name" : "Test Demo", "email" : "test@demo.com", "url" : "http://test.com/" };
Or you can shorten that all into a single string, and npm will parse it for you:

"Test Demo (http://test.com/)"
Add following content to your package.json file :-

{
  "name": "MY DEMO APP",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.2",
    "get-age": "^1.0.1",
    "json-stringify": "^1.0.0",
    "jsonwebtoken": "^8.1.1",
    "md5": "^2.2.1",
    "moment": "^2.20.1",
    "mongoose": "^5.0.2",
    "mysql": "^2.15.0",
    "randomstring": "^1.1.5"
  }
}
Tags

Post a Comment

0Comments
Post a Comment (0)