Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance.
In his poem "The Rainy Day", Longfellow concludes "Into each life some rain must fall, Some days must be dark and dreary". While the poem starts our gloomy, it ends with the realization that everyone has to deal with dark things at times in their lives but at the end of every one of them, there is hope and sunshine. It seems to me that it is easy to fall into a funk but so difficult to get out of it. I think we can allow ourselves to dwell on the gloomy and dark things a bit too much and we miss the fact that God is there waiting and wanting to help us. We can sometimes get lost in our sadness and can no longer see a way out and then fall easy prey to temptations.
God promises to us that there is always a way out as we read in 1 Corinthians 10:13, "No temptation has overtaken you except what is common to mankind. And God is faithful; he will not let you be tempted beyond what you can bear. But when you are tempted, he will also provide a way out so that you can endure it.". Notice that it doesn't say He will do this for you sometimes but that there are some things He just won't help you with. He will not abandon you. He has a plan for you. He loves you more that you can really understand. Like the sun behind the clouds in Longfellow's poem, He is there. If He is there when we fail Him, how much more will He be there when we are hurting? Some trials are really hard to bear. Regardless of what we know and how hard we try to maintain our faith, some hard times are just going to hurt. And then we can get easily confused and angry and ask God what He thinks He is doing. But as James points out, these trials are designed to build our trust in God. Rather than go it alone, believe in your faith, trust in it, and seek God all the more.
If we remember Romans 8:28, "And we know that in all things God works for the good of those who love him, who have been called according to his purpose", we can make it through anything. There is some purpose in our dark days, ones we may not understand just yet. But God is love and is always there for each and every one of us. Seek Him out even more so in the dark times and He will show you the way.