And why was it the only language in the browsers? And why did it spread to servers?
Well, what alternative was there? At the time for the bowser - none as far as I remember. For the server ... Java was bloated and PHP even more ugly. So I also choose node.
> And why was it the only language in the browsers?
Nobody wanted to implement another language which would have broken cross browser functionality for animating menus on HTML pages.
> And why did it spread to servers?
Because frontend devs didn't want to learn another programming language.
> Java was bloated and PHP even more ugly. So I also choose node.
So you chose an environment that was slow, single-threaded, had an immature ecosystem, callback hell, and was difficult to debug. To each their own I guess.