How To Create Package.json - React.js

package.json

In order to add dependency packages to your project, you need to create package.json file. This file is used to store the metadata associated with that project as well as to store the list of dependency packages.

The benefits of having package.json file are described below.

  • It describes all the packages that your project depends upon.
  • This file makes it easy to make the build reproducable so that it can be shared with other developers. 

Reference https://docs.npmjs.com/getting-started/using-a-package.json

Creating "package.json"

Open Command Prompt.

Navigate to the directory in which you want to create package.json.

Run the following command

> npm init

Press enter for the list of questions to get initiated and type "yes" to create the package.json file.

 
 

The file will be created in the respective directory and it looks like the below screenshot.

  • name default is set to author name unless in a git directory, in which case, it will be the name of the repository
  • version always 1.0.0
  • description default is set to empty string
  • main always index.js
  • scripts by default, creates an empty test script
  • author default is set to empty string
  • license ISC 

Specify dependent packages

Navigate to the directory and edit package.json manually.

You could add 2 types of packages, as shown below.

  •     "dependencies": packages required by your application in production
  •     "devDependencies": packages required for development and testing

Ebook Download
View all
Learn
View all