Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

What is package.json in node.js ?

  • Last Updated : 21 Oct, 2021

When we discuss software, application, product, etc. We often see the description that is provided by the owner so that others can understand that entity i.e. name, model, version, owner, etc. Similarly, NodeJS provides a package.json file that tells information about the application. 

package.json: This document contains various metadata of the entire node application, it consists of key-value pairs in actual JSON format. This file is enough to describe the whole project. The details which are included in this are listed below,

  • name: This is the most important field of a project, it consists of the name of the package.
  • version: This denotes the current version of the package. The name along with the version uniquely identifies the package.
  • description: It is a string, each package have their certain functionality and it is good to tell about the brief description.
  • keywords: An array of strings that contains certain keywords relevant to the package.
  • homepage: It is the homepage of the package
  • licens: It is used to specify the licenses, mainly used to tell about the peoples for restrictions on how they can use this package.
  • main: It consists of the entry point to package, like which file should run in the start.
  • authors/contributors: These are the name of the author of the package and the contributors.
  • repository: This consists of the repository on which the package is stored.
  • scripts: These are some of the scripts which are useful to run the package.
  • config: It consists of some configurations about the package.
  • dependencies: These are the set of dependencies that are necessary to use the package successfully.

Initializing the package.json in the project:

We can use the command provided by npm or yarn package manager to initialize this package.json,

npm init 

This would ask for few configurations which are listed above and we can fill them easily according to our package, We can also initialize with default configurations by using the -y flag.

npm init -y

Note:- We can also manually change and create the package.json but it is not the preferred way to do this.

Example:- Here we are going to illustrate these concepts with the help of an example of an eCommerce NodeJS application. With this, you can get a clear picture of the above discussion. Before doing this make sure that you have npm or yarn package manager installed on your system.
Explanation:-  First of all we have started initializing the package with npm init and then it is asking for some details like the name which was came auto-filled according to a directory name, the description, the entry point from which our server will be going to start, the keywords related to the package, and the name of the author, etc. The GIF below shows how this all process works and creates a package.json file.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!