53. What are devDependencies and dependencies in package.json?

In the package.json file, dependencies and devDependencies are sections that define the external libraries required by the project.

dependencies:

  • Description: These are packages required to run the application in a production environment. They typically include libraries that are essential for the application to function, such as express for a server application.
  • How to add:
npm install <package-name> --save
  • Example in package.json:
"dependencies": { "express": "^4.17.1" }

devDependencies:

  • Description: These are packages required only during the development of the project and are not needed in a production environment. They include testing, compiling, building tools, and other development utilities like jest or webpack.
  • How to add:
npm install <package-name> --save-dev
  • Example in package.json:
"devDependencies": { "jest": "^26.6.3", "webpack": "^5.24.4" }

Differences:

  • dependencies: Installed when the project is deployed on a production server.
  • devDependencies: Installed only in a development environment.

The distinction between dependencies and devDependencies allows for efficient dependency management, ensuring that only necessary packages are deployed to the production environment.

devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.