Zera met Rav Judah standing by the door of his father-in-law’s house and saw that he was in a cheerful mood, and if he would ask him all the secrets of the universe he would disclose them to him. He accordingly asked him: Why do goats march at the head of the flock, and then sheep? — Said he to him: It is as the world’s creation, darkness preceded the light. Shabbos 77a
This is an analogy to the Empire of Greece, who are compared to goats,which brought darkness to Israel, and Israel is compared to sheep, who vanquished the darkness with the light discovered by the Chashmonayim, in their rededication of the Beis Hamikdash. 
Rabeinu Yonah 2:5 states:
He who trusts in God must yearn from depths of his pain, for the darkness is the cause of the light, as the navi states: Rejoice not against me, O my enemy; though I am fallen, I shall arise; though I sit in darkness, the LORD is a light unto me Michah 7:8. And our sages taught, Had I not fallen I would not have risen, had I not sat in darkness, I would not have found light.)
Zeh Hashaar explains: The darkness is the cause of the light: This is the pathway of Divine Providence, for if Hashem desires to give a person, or the world, any good, then beforehand He tests him, as Chazal teach in Medrash Rabba on the verse,
And Moshe returned unto the LORD, and said: ‘Lord, wherefore have You dealt ill with this people? why is it that You have sent me? Shmos 5:22
Hashem answered: I am working to crown his son in Egypt, and he says to me, Wherefore have you dealt ill with this people? Thus it is said: My ways are hidden.
How can darkness be the cause of light? The light was the Ohr Haganuz-the Hidden Light, and Hashem hid it for the righteous in the World to Come. Where is the light hidden? It is hidden in the darkness itself. And anyone who wants to find the light has to delve into the darkness, and find the light. Then the Ohr Haganuz will be revealed. One has to delve into the loneliness within himself and discover the aloneness and uniqueness, for which he was sent into the world.
God wove chomer –darkness, as well as tzurah—light, into the fabric of creation when He said, And God called the light Day, and the darkness He called Night. And there was evening and there as morning, one day.” Breishis 1:5.
The new Jewish day starts at nightfall because night represents loneliness, crisis, darkness, chomer, Yetzer Hara— disconnection, and distance from God.
The Torah states And he said: ‘Lay not Your hand upon the lad, neither do thou anything unto him; for now I know that you are a God-fearing man, seeing that you have not withheld Your son, your only son, from Me. (Breishis 22:12)
חֹשֶׁךְ—darkness, comes from the word חָשַׂכְתָּ—which means to hold back.
The word חָשַׂכְתָּ is translated by Onkelos as מנעתא—you held back. From here we can understand that the function of darkness is that it “holds back” the light. The night creates a spiritual darkness and aloneness, as if the light—reality—is withheld from us. It is as if creation is held back from us and we are lost in confusion as we find it hard to find our way in the darkness. The pathway forward is not clear. We are forced to stand still, without a future pathway, without continuity. Darkness holds back the light. It prevents the light from coming forth. Darkness is the absence of light—it is left alone–without light. In the dark, one feels existentially alone, abandoned, afraid. Darkness leads to emotional loneliness.
The medrash states: If I hadn’t fallen I would not have risen. The darkness is the cause of the light. The light comes because of the darkness.
Tanchuma (Noach) states: the nation that walks in darkness shall see a great light. This means that the darkness is the cause of the light. This does not mean that light banished the darkness; rather the darkness transforms itself into light, itself. The light arises from within the darkness. We have to go to war against the darkness within ourselves—meaning the loneliness within ourselves can be transformed into aloneness, uniqueness and independence.
 Maharsha Chidushei Aggados Shabbos 77b
 Medrash Tehillim 22
 Medrash Tehillim 22
This article is an excerpt from Alone Against the World-the Torah Antidote to Loneliness by Rabbi Yisroel Roll.