Home » Difference Between composer.json And package.json

Difference Between composer.json And package.json

Last updated on May 25, 2021 by

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 the vendor 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:

  1. How to Select Data Between Two Dates in MySQL
  2. Error After php artisan config:cache In Laravel
  3. Specified Key Was Too Long Error In Laravel
  4. AJAX PHP Post Request With Example
  5. How To Use The Laravel Soft Delete
  6. How To Add Laravel Next Prev Pagination
  7. cURL error 60: SSL certificate problem: unable to get local issuer certificate
  8. Difference Between Factory And Seeders In Laravel
  9. Laravel: Increase Quantity If Product Already Exists In Cart
  10. How To Calculate Age From Birthdate
  11. How To Check Laravel PHP Version
  12. How To Handle Failed Jobs In Laravel
  13. How To Remove WooCommerce Data After Uninstall
  14. How To Get Latest Records In Laravel
  15. 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!

 
 

Leave a Comment