How to install a module programmatically in Drupal 8?

There might be a situation when you have to install a module programmatically in Drupal 8. You can achieve this with the help of Drush Invoke command. Make sure Drush is working fine on your system before using this function.

//This command will install and enable both devel and admin toolbar.

drush_invoke('pm-enable',['devel','admin_toolbar']);

Tags