The answer to 'how to prevent pest' is to take a comprehensive approach to pest control by implementing a combination of preventative measures. This includes sealing up entry points, removing food and water sources, and using targeted treatments when necessary.
Start by inspecting your home and yard for any cracks, holes, or gaps where pests could potentially enter. Seal these up with caulk, steel wool, or other appropriate materials. Make sure to repair any damage to screens, windows, and doors. Eliminate sources of food and water by storing food in airtight containers, cleaning up spills and crumbs, and fixing any leaks or standing water. You can also use natural repellents like essential oils or diatomaceous earth in problem areas.