Tolkien, a professor at Oxford University at the time he began writing the book, said that it began from a single senseless sentence ("In a hole in the ground there lived a hobbit") scrawled on an exam paper he was grading. When he began, he did not intend to connect the story with the much more profound mythology he was working on allready back then.
However as Tolkien continued writing it, he decided that the events of The Hobbit could belong to the same universe as The Silmarillion, and he introduced or mentioned characters and places that figured prominently in Tolkien's legendarium, specifically Elrond, Gil-galad and "Gondolin". (here is your answer) Taken into consideration with the rest of Tolkien's work, The Hobbit serves as both an introduction to Middle-earth as well as a narrative link between earlier and later events as told in The Silmarillion and The Lord of the Rings, respectively.
As remarked above, Tolkien substantially revised The Hobbit's text describing Bilbo's dealings with Gollum in order to blend the story better into what The Lord of the Rings had become. This revision became the second edition, published in 1951 in both UK and American editions.
Funny enough allthough Tolkien himself introduced the revisions to the publisher even he himself was quit surprised to "really" see them enter the books. Maybe this act pushed Tolkien to work on and finish The Lord of the Rings, as did the friendshipa dn guidance of C.S. Lewis.
Hope this replies to your questions. Cheers, B.