DEV Community

Hasan Zohdy
Hasan Zohdy

Posted on

2-Nodejs Course 2023: Package.json file

🔥 Package.json

The package.json file is the most important file in your project. It contains all the information about your project, including the dependencies, scripts, and other metadata.

The package.json file is a JSON file that contains the following properties:

  • name: The name of your project.
  • version: The version of your project.
  • description: A short description of your project.
  • main: The entry point of your project.
  • scripts: A collection of scripts that you can run using npm or yarn.
  • keywords: A list of keywords that describe your project.
  • author: The author of your project.
  • license: The license of your project.
  • dependencies: A list of dependencies that your project needs to run.
  • devDependencies: A list of dependencies that your project needs to run in development mode.
  • peerDependencies: A list of dependencies that your project needs to run in production mode and are not installed automatically.
  • repository: The URL of the repository of your project.
  • bugs: The URL of the issue tracker of your project.
  • homepage: The URL of the homepage of your project.

Scripts

The scripts property is a collection of scripts that you can run using npm or yarn. The scripts property is an object that contains the name of the script as the key and the command to run as the value.

For example, the following script runs the start script using npm:

npm run start
Enter fullscreen mode Exit fullscreen mode

The following script runs the start script using yarn:

yarn start
Enter fullscreen mode Exit fullscreen mode

The command start will call the start script in the scripts property of the package.json file.

Dependencies

The dependencies property is a collection of dependencies that your project needs to run. The dependencies property is an object that contains the name of the dependency as the key and the version of the dependency as the value.

For example, the following dependency installs the fastify package:

"dependencies": {
  "fastify": "^3.24.1"
}
Enter fullscreen mode Exit fullscreen mode

This will install fastify version 3.24.1 and all its dependencies.

Dev Dependencies

The devDependencies property is a collection of dependencies that your project needs to run in development mode. The devDependencies property is an object that contains the name of the dependency as the key and the version of the dependency as the value, as it is only needed in development mode.

For example, the following dependency installs the typescript package:

"devDependencies": {
  "typescript": "^4.5.4"
}
Enter fullscreen mode Exit fullscreen mode

This will install typescript version 4.5.4 and all its dependencies.

Peer Dependencies

The peerDependencies property is a collection of dependencies that your project needs to run in production mode and are not installed automatically. The peerDependencies property is an object that contains the name of the dependency as the key and the version of the dependency as the value thus all packages in the peerDependencies property must be installed manually.

Other Properties

The rest of the properties are mostly self-explanatory. The main property is the entry point of your project. The repository property is the URL of the repository of your project. The bugs property is the URL of the issue tracker of your project. The homepage property is the URL of the homepage of your project.

🎨 Conclusion

In this lesson, we learned about the package.json file. We learned about the scripts property, the dependencies property, the devDependencies property, and the peerDependencies property. We also learned about the other properties of the package.json file.

🎨 Project Repository

You can find the latest updates of this project on Github

😍 Join our community

Join our community on Discord to get help and support (Node Js 2023 Channel).

Latest comments (0)