Religion, with its various teachings about an afterlife, is the traditional way people have coped with knowledge that they will die. The other popular method is parenthood. In this way, people know part of them will live on in their offspring. However, there have always been those for whom religion and children have not been enough to soothe death anxiety. They try to make an immortal legacy through conquests, monuments, inventions, discoveries, great works of art, or other achievements. The growth of scientific knowledge has eroded religious belief, and so denial has become the most popular method of dealing with death anxiety, at least in the industrialized world (the panic over COVID-19 made that clear).
In my view, all these methods are wrong. The first step is to acknowledge that not only do we die, but we will almost certainly be forgotten not long after. There are only a few hundred people still remembered millennia after their deaths. Even if we have children, whatever was unique about our DNA will be diluted to insignificance after a few generations. There are people who try to attach their identity to a nation or even the human race as a whole, but even that is flawed. Nations come and go. Few last more than a few centuries. If humanity follows the same path as 99% of other species, it will go extinct within a few million years.
I find solace in looking at the natural world. Through evolution, every living thing is related to me in some way, and this has been proven through DNA analysis. Life on earth has survived for billions of years through many cataclysms, and it will almost certainly continue into the far future regardless of what humans do. Everyone could benefit from looking at the big picture as shown in natural history museums. Enjoy the moment. Don't cry because it's over, smile because it happened. Life finds a way.
