In this blog, We will outline use of composer as a dependency manger for Drupal modules and themes.
Below command is used for downloading modules at the root folder of your Drupal installation
$ composer require drupal/<MODULE_NAME>
You can use either the project name, or the specific module name within a project when requiring a module. Composer will download the whole project that contains a particular module.
You can also download specific version of module, For that use below command
$ composer require drupal/<MODULE_NAME>:<VERSION>
By default Composer downloads all packages in “Vendor” folder, but most of the time we want to download modules, themes and libraries to respective folders.
To overcome this problem, you need to update composer.json located at root folder
"extra": { "installer-paths": { "core": ["type:drupal-core"], "libraries/{$name}": ["type:drupal-library"], "modules/contrib/{$name}": ["type:drupal-module"], "profiles/contrib/{$name}": ["type:drupal-profile"], "themes/contrib/{$name}": ["type:drupal-theme"], "modules/custom/{$name}": ["type:drupal-custom-module"], "themes/custom/{$name}": ["type:drupal-custom-theme"] } }
From Drupal 7, it supports composer search function as well, So you can search from drupal modules using command line, for this you can use below command
$ composer search <MODULE_NAME>
reference :- https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies