It's essential to clarify that fruit flies are not entirely harmless
Fruit flies are also attracted to the same sugars in fruit juices and the fermenting sugars.
While there are fruit fly-killing sprays that you can purchase, these contain chemicals you may want to avoid introducing into your home.
One other trap that can be effective is an almost-empty red wine bottle.
A third option for a simple homemade trap for fruit flies is adding ripe fruit or juice into a jar.
There are also helpful methods to eliminate them once they have invaded a home.