Digital nomad taxes – which country to pay in?

If an American lives in one country (e.g. Spain) while working for an American startup and being paid in US dollars, should he pay taxes in the US or Spain, or both? In Europe the national health care systems are tied to paying taxes in a country. How are nomads dealing with health insurance? I’d really love to be completely above board w/r/t taxes and have health insurance, but all the advice I find online either sounds made-up or is “consult with your accountant”. If I had an accountant I wouldn’t be searching for this info!