I've been raising meal worms since March and learned some hard lessons! I had a MEGA grain mite infestation that I finally have under control. So here's my best advice for beginners:
1. Use wheat bran for your substrate. I've tried using oatmeal but noticed they eat the wheat bran and pretty much ignore the oatmeal. I know others use oatmeal but my experience is they prefer the wheat bran. I've also used oat bran (not oatmeal) and wheat bran in the same bin.
2. Moisture is your enemy! After my grain mite nightmare, I now use only carrots for moisture for the worms and the beetles. Wipe extra moisture off the carrots before placing in bins. Apples and potatoes have too much moisture and again, I noticed they preferred the carrots over apples and potatoes and apples attract fruit flies.
3. Be sure and remove old carrots before adding new ones. Don't let old carrots just sit in the bin and start to mold.
4. Ventilate! I had lids with holes on my bins but it wasn't enough and that's how the grain mites took hold. I now do not have any lids on my bins. Too much moisture and too little ventilation was all it took for the grain mites to explode and take over the bins...and I'm talking billions of the tiny things!
5. Freeze substrate before using! I buy my wheat bran in bulk and that's where the grain mites came from in the first place. I've since learned that you should always freeze the substrate for at least 3 days before using to kill any mites it may contain. You can also bake it in thin layers at 225 degrees for at least 10 minutes but that takes time to bake enough of it so I now just freeze it.
I have not had any issues with flies or moths or other bugs in my meal worms other than the nasty grain mites.
All I know is I wish someone had given me the above advice before I started raising meal worms. I could have avoided having to throw out bins of worms and pretty much having to start all over.
The upside is that my hens really do love eating the live meal worms which is what makes the trouble I went through worth it in the end.