As on any ship, be that merchant or military they would have shifts or "watches" usually 8 hours on 8 hours off. There would be Officers of the Watch (OOW) who would have command while the Captain slept. If anything happened that the OOW decided needed to be escalated he would wake the Captain and have him come to the bridge.
You see this in the next generationTNG Thine Own Self when Counsellor Troi decides to take the exam to qualify as a watch officer after finding out that Doctor Crusher was in command one time. I cannot recall the name of the episode.