Generally, a house, with a door and a light source, is best. You can also protect yourself by surrounding yourself with blocks and placing down a single torch to light the area you are hiding in. Finally, you may also craft a bed and use to sleep until daytime, if the bed is in a safe area.