Some advice coming from someone who dealt – and is still often dealing – with anxiety, depression, and low self-esteem.
The very first thing you have to understand is that your perception is biased by your mental issues, is your feeling of incompetence backed by any facts? Is your boss continually complaining about your performance? And even if your performances are as bad as you think they are, I wouldn't be surprised since you seem to hate every moment of your life.
From how you described yourself, I don't see a loser, I see a 43 years old man who's going through a lot of sacrifices to provide for his family, I'd call that courage. I don't see a loser, I see someone with a serious case of depression, everything you described ticks all the boxes.
There is no magic pill to get you out of that, and coping mechanisms only goes so far. You need therapy, plain and simple, and, if possible, time off your job.
Start doing things you enjoy, don't code because you have too, maybe you're at a time in your life where code isn't what you want to do anymore, and that's fine, no shame in that, or maybe you just need a little time off. Many men completely turn their lives around in their 40s, it's not too late, but you have to take risks, you have to try new things, physical activity such as weightlifting is usually great because it'll raise your testosterone levels, but you can also start things you never thought you'd want to try: music, dance, writing, astrophotography, bird watching, anything.
Just remember this: your thoughts are not logical, it's not your analytic brain that's telling you you're worthless, it's depression, and pardon my French by depression is a bitch, it's that asshole of a friend, always in your head telling you just how much of a failure you are even when it's untrue.
Don't isolate yourself from people who care, there are more than you think and they need to know what you're going through. Seek medical help, and take it easy, friend.
"It gets easier. Every day it gets a little easier. But you gotta do it every day —that’s the hard part. But it does get easier."