Forty is often that turning point in life where the end starts to look closer to the beginning. You have a lot more of your life to look back at and less to look forward to. We joke about mid-life crises, but they're a real thing.
The OP sure sounds to me like they're going through exactly that, and children have become a fixation.
And if they're struggling with anxiety and depression now, I can't imagine what they'd go through as a parent.
At minimum, they should not be making any decisions until they get a little healthier. First, it's very unlikely any decision they take, today, would be rational. And second, if they did choose to become a parent, they'd be doing so at a time when they're incredibly mentally and emotionally fragile, which is a recipe for disaster.
I'm not going to psychoanalyze someone by a single text message, but I also thought it was unusual to swing that hard. Probably the decision was not thought well and hence the regret, maybe the neighbors have beautiful babies and FOMO brings regret, maybe it's a mid-life crisis where we worry about our legacy, only they know.
I can only contribute my experience deciding not having kids. We both agreed to not have them, we're 50 now, the window has closed indeed for us, and we don't regret that decision at all. It's fantastic to age together and be the center of our own little family. What little need for forging a malleable mind is left, is fulfilled by the sporadic visits to/from our nephews and nieces.
Whatever OP does, I hope he doesn't do it on impulse. It's immensely better to regret not having kids, than regret having them.
It makes me laugh when people talk about having a "legacy"
99.999% of people are unremarkable. There are currently just over 1M Wikipedia articles about living people. Meanwhile, there are 7.7B people on the planet. Even if you made the incorrect assumption that all 1M were about living Americans, with the US population being nearly 330M, that means you'd have to be in the top 0.3% to even have a Wikipedia article about you.
Unless you become the CEO of a Fortune 500 company or at least a state-level politician, or become a high-profile criminal, you will probably be forgotten entirely within three generations of your death.
It surprises me that some people have a hard time coming to terms with this.
Your children will have 1/2, or .5, of your DNA. Your grandchildren will have .25, great-grandchildren will have .125, then .0625....after 10 generations (about 300 years), your descendents will have 0.000977 of your DNA. After 30 generations (900 years) your descendents wil have 0.000000000931 of your DNA.
What kind of "legacy" are people thinking that they are leaving behind? All traces of your DNA will effectively disappear from all your progeny. You are gone, not a trace. Your DNA vanishes.
I might never have a wikipedia article about me, but at least I had kids and they will have kids and so on. Of course, I will eventually be forgotten (I don't know who my great great grandparents were) but if it weren't for them I would not be here today. One of the defs is " something transmitted by or received from an ancestor or predecessor or from the past".
It is something special. I have a kid now and another coming in the next few weeks. It is both the most time consuming and expensive thing I can do but also the most meaningful. I never thought I would feel this way 5 years ago. It is definitely dismissive to tell someone hey your feelings are rooted in other problems. It is not like OP is longing for a cupcake or something. So I support the OP and if it is really something you need, do it!