Open In App

What is package.json in node.js ?

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,



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.

Article Tags :