I am installing a new vanity light. I took down the old one from 1997 and found that there is no box behind the light, only the cable coming through the drywall, (black, white and green/ground.) Is it okay to just hook up the new fixture to this set up? Why would there be a need for a box?
The question depends entirely on whether the fixture acts as its own junction box, with full containment and a strain relief clamp. If it includes a UL listed enclosure, all good. The instructions should make this fairly clear.
If not, grab an old work (remodeler) box and pop it in. Be sure you'll clear your studs before you start cutting drywall.