There are times when you may find yourself wanting to use Composer in order to manage the dependencies on a particular Drupal installation. If Composer was not installed during the installation of the Drupal site, then you will either need to manually make a change, or you can use a plugin to get Composer properly configured.
This article applies to Drupal 8 sites that were originally installed without using Composer.
Using the Composerize Plugin
The easiest way to get Composer properly configured to use with your Drupal site is to use the Composerize plugin. You can download it and then get installed on your site. To learn more about the plugin, please see the plugin documentation from their github location.
Once you have the plugin installed it will automatically generate an updated composer.json file. The Composerize plugin will add contributed modules, themes, and profiles that it finds on your site.
The Composerize plugin will create a composer.json file from your installed Drupal codebase.
Manually Editing the Composer.json File
Manually editing your Composer.json file to add the Composer can be a very lengthy endeavor. Drupal.org has graciously put in a step-by-step document for Adding Composer to an Existing Site. These steps will take you through the manual exercises required to get your site working with Composer.