I had an accident 8 years ago and was not injured but now I have a headache very painful at night. The pain is severe and happens like nerve attack?

Neurological. Chronic pain of headache years after an accident tends to rule out a cerebral process. Speculation arises for a chronic cervical soft tissue (ligament, tendon, muscle) injury. Increased pain when lying down supports this hypothesis; as certain muscles bear increased portion of head weight in this position. Neurologist or osteopath best specialists to consult.
Consider these: Agree that you could benefit from specialty consultation. Some explanations include cervical spine disorder, jaw or dental problems, occipital neuralgia, thoracic outlet syndrome, or true cluster headache syndrome. Cannot relate this to your former accident.