Nuclear weapons prevent an all-out invasion, but they're not much good at anything else. The US, for example, could not have used nuclear weapons in Afghanistan or Iraq.
The US is something of an outlier. Most countries maintain much smaller militaries. They have them on hand for a variety of purposes: disasters, foreign peacekeeping, border patrol, and keeping their hand in Just In Case.
NATO countries, for example, are supposed to keep militaries so that Russia doesn't get any ideas. Say, Wagner troops meander across the border into Poland. Russia clutches its pearls and says, "Oh, no, don't end the entire world by nuking us even though it's obvious that we ordered it." So troops would get sent... which is why it never actually happens.
How much military you need to achieve that is up for debate. The US often claims that other NATO countries need more, and that the European countries are relying on America to provide most of that deterrent. But the US is almost certainly providing way, way, way more deterrent than is needed -- more about national preening than serious consideration of needs.