Let’s say if USA didn’t have nuclear weapons, do you think countries like North Korea or China would have NOT waged war on Americans? Of course, they would have! But since USA has these mass destruction weapons, the other side will probably not make any attack out of fear of retaliation.
Admittedly, weapons can lead to violence and wars. But it’s just as much for peace. It keeps enemies at bay and protects the homeland. And this is one if the main reasons why countries like USA, India and others have piled up nuclear weapons. To protect their nation from any harm!
Now, there also few countries that have produced/are producing nuclear weapons without full disclosure, including Israel, which could be a possible threat. (Of course, threats from North Korea always loom high.)
Civility and mutual understanding between countries is a thin knot that’s protecting humanity from the harms of nuclear. And major organizations like UN are playing a major role behind this.So yes, the reason why US and so many other countries have produced nuclear weapons is to protect their countries and put enemies at bay, hence preventing war.