The roasting provides the flavour and aroma. It is considered something of an art and timing is key: it usually takes between 7 and 14 minutes depending on the desired coffee (espresso takes the longest).
Beans ’pop’ like corn as the heat increases. Once roasted, beans lose their freshness quickly, so most roasting occurs in the country of consumption.