How to set event listenet for ‘Enter’ key in textarea with js [duplicate]

I am making a terminal themed website

so far I tried this

    textArea.addEventListener('keypress', function (e) {
      if (e.key === 'Enter') {
        runCommand(textArea.value);  
        textArea.value = "";
      }
    })

but after the running one command Textarea cursor moves to a new line and switch case stops working
how to reset the Textarea totally or use enter key without moving to new line?