40 Years in the Desert: The Story of Israel is Recorded for Our Instruction
The story of Israel spending 40 years in the desert is recorded for us as a lesson and a warning. God does not want us to make the same mistakes they made.
His desire is that we learn to live not by bread alone but by every word of God. To this end we are given the bread from heaven through Jesus Christ. The manna given to Israel in the wilderness did not lead them to everlasting life.
Specifically we are to be on guard against: idolatry, sexual immorality, testing God, and murmuring against God. These warnings are illustrated in the record of the golden calf, the seduction of the Moabite women, Israel's cries for water, and the rebellion of Korah.
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.”