Seems like a good way to avert a midlife crisis is to explicitly make helping others a non-trivial part of one's life. Focusing on effectiveness on helping others is probably an important component as well.
I recommend looking into Effective Altruism - "a philosophy and community focused on maximising the good you can do through your career, projects, and donations"
In my case I've joined Giving What We Can ten years ago - giving at least 10% of my income to cost-effective charities. No matter how badly my day goes, I can always reflect on how nice it is that through my donations thousands of individuals have benefited greatly.
I recommend looking into Effective Altruism - "a philosophy and community focused on maximising the good you can do through your career, projects, and donations"
https://www.effectivealtruism.org/
In my case I've joined Giving What We Can ten years ago - giving at least 10% of my income to cost-effective charities. No matter how badly my day goes, I can always reflect on how nice it is that through my donations thousands of individuals have benefited greatly.