However I realise it may not always be so easy. So:
- I'm self employed. Foreign companies aren't going to set up a branch office just to employ me. Purchasing my services however is easy.
- I've niched down to a business vertical, and I'm starting to niche down more technically as well. No more "I'm a full stack developer with a track record of delivering results across multiple industries".
- I write software for the agricultural sector. It's not an industry that tends to cluster as much in big cities. A lot of companies are based in regional areas, and it's not realistic for them to source all the talent they need locally. People are open to networking online.
It's not a raging success yet but it's a lot better than working in an office everyday in the city was for me.
YMMV if you live in a US tech hub.