In hook_form_alter how can I attach libraries on frontend only? I'm trying to attach a js file to a form using hook_form_alter() but I don't want to js to be loaded on the administration template.

How can I achieve something like this? With what do I need to replace the THEME != ADMINTHEME part in the following code snippet?

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if (($form_id == 'node_CUSTOM_edit_form' || $form_id == 'node_CUSTOM_form') &amp;&amp; THEME !== ADMINTHEME) {
    $form['#attached']['library'][] = 'MYMODULE/myLib';
  }
}
To answer your question, you can get the active theme name using below code in module file.

$activeTheme = \Drupal::service('theme.manager')-&gt;getActiveTheme()-&gt;getName()

and check if $activeTheme !== 'Your admin theme'.

Recommended way:

In your case as you want to add library specific to theme, it should be added in theme file and not module file.