Often, the developers get confused between composer.json and package.json because they look similar but actually different in working and contain different data.
So in this tutorial, we will learn the difference between the composer.json and package.json file. Most of the users found these files in the Laravel root directory. The package.json file is usually found in the JavaScript Framework project like AngularJs, VueJs, React, NodeJs, etc.
Let’s see how composer.json and package.json is differ from each other.
Difference Between composer.json And package.json
01 composer.json
- Composer is a package management tool for PHP. So
composer.json
manages the PHP dependencies - For Example, The command
composer require fzaninotto/faker
will open and write to the composer.json file and download all the dependencies - Composer resolves all dependencies listed in your
composer.json
file and downloads the latest version of their files into thevendor
directory in your project - When Composer has finished installing, it also generates the
composer.lock
file and write all the package information with the version in this file.
Example Of composer.json
{
"repositories": [
{
"type": "composer",
"url": "http://packages.example.com"
},
{
"type": "composer",
"url": "https://packages.example.com",
"options": {
"ssl": {
"verify_peer": "true"
}
}
},
{
"type": "vcs",
"url": "https://github.com/Seldaek/monolog"
},
{
"type": "package",
"package": {
"name": "smarty/smarty",
"version": "3.1.7",
"dist": {
"url": "https://www.smarty.net/files/Smarty-3.1.7.zip",
"type": "zip"
},
"source": {
"url": "https://smarty-php.googlecode.com/svn/",
"type": "svn",
"reference": "tags/Smarty_3_1_7/distribution/"
}
}
}
]
}
02 package.json
- package.json manages the Node dependencies
- All npm packages contain a file, usually in the project root, called package.json – this file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project’s dependencies.
- For Example, The command
npm install datatables.net
will open and write to the package.json file and download all the dependencies - NPM installs all the dependencies to
./node_modules
.
Example Of package.json
{
"name" : "underscore",
"description" : "JavaScript's functional programming helper library.",
"homepage" : "http://documentcloud.github.com/underscore/",
"keywords" : ["util", "functional", "server", "client", "browser"],
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
"contributors" : [],
"dependencies" : [],
"repository" : {"type": "git", "url": "git://github.com/documentcloud/underscore.git"},
"main" : "underscore.js",
"version" : "1.1.6"
}
Additionally, read our guide:
- How to Select Data Between Two Dates in MySQL
- Error After php artisan config:cache In Laravel
- Specified Key Was Too Long Error In Laravel
- AJAX PHP Post Request With Example
- How To Use The Laravel Soft Delete
- How To Add Laravel Next Prev Pagination
- cURL error 60: SSL certificate problem: unable to get local issuer certificate
- Difference Between Factory And Seeders In Laravel
- Laravel: Increase Quantity If Product Already Exists In Cart
- How To Calculate Age From Birthdate
- How To Check Laravel PHP Version
- How To Handle Failed Jobs In Laravel
- How To Remove WooCommerce Data After Uninstall
- How To Get Latest Records In Laravel
- How To Break Nested Loops In PHP Or Laravel
That’s it from our end. We hope this article helped you to understand the difference between composer.json and package.json
Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you for reading this post 🙂 Keep Smiling! Happy Coding!