How did Frodo know where the Bree village was?
I've never read the books, but in the movie Gandalf just tells Frodo go to Bree expecting Frodo to know where that is.
So if Frodo knows where Bree is, how does he know?
This is one of the differences between the books and the films.
In the books, Gandalf simply tells Frodo to head for Rivendell. He never mentions Bree at all.
‘No indeed!’ said Frodo. ‘But in the meantime what course am I to take?’
‘Towards danger; but not too rashly, nor too straight,’ answered the wizard. ‘If you want my advice, make for Rivendell. That journey should not prove too perilous, though the Road is less easy than it was, and it will grow worse as the year fails.’
‘Rivendell!’ said Frodo. ‘Very good: I will go east, and I will make for Rivendell.
The Lord of the Rings Book One, Chapter 2: The Shadow of the Past
Page 66 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
Frodo hasn't been to Rivendell, but he knows of it from Bilbo's stories of his great journey. He will know that if he follows the Great Road east out of the Shire, he will reach Rivendell.
He probably also knows that he will pass through the village of Bree on the way to Rivendell. The hobbits of the Shire know of Bree; the Shire was founded by hobbits who traveled from Bree.
About this time legend among the Hobbits first becomes history with a reckoning of years. For it was in the one thousand six hundred and first year of the Third Age that the Fallohide brothers, Marcho and Blanco, set out from Bree; and having obtained permission from the high king at Fornost, they crossed the brown river Baranduin with a great following of Hobbits. They passed over the Bridge of Stonebows, that had been built in the days of the power of the North Kingdom, and they took all the land beyond to dwell in, between the river and the Far Downs.
The Lord of the Rings Prologue, Section 1: Concerning Hobbits
Page 4 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
Although that was about 1,400 years ago, there are still a few Shire hobbits (mainly from the East Farthing and Buckland) who visit Bree. When Frodo and his companions are approaching Bree, Merry tells them
‘There are hobbits in Bree,’ said Merry, ‘as well as Big Folk. I daresay it will be homelike enough. The Pony is a good inn by all accounts. My people ride out there now and again.’
The Lord of the Rings Book One, Chapter 8: Fog on the Barrow-downs
Page 148 (Houghton Mifflin Harcourt; Single Volume 50th Anniversary Edition)
Gandalf would know that Frodo is aware of the existence of Bree and that he at least knows it lies to the east of the Shire. There is only one main road leading east from the Shire, so Frodo should have no trouble finding it.
If Frodo was unsure of the way, he would presumably ask Gandalf for directions. As he doesn't, we can assume that he knew how to get there.
In the book, Tom Bombadil tells them, although they certainly already knew of Bree beforehand.
All the same the hobbits wished he was coming with them. They felt that he would know how to deal with Black Riders, if anyone did. They would soon now be going forward into lands wholly strange to them, and beyond all but the most vague and distant legends of the Shire, and in the gathering twilight they longed for home. A deep loneliness and sense of loss was on them. They stood silent, reluctant to make the final parting, and only slowly became aware that Tom was wishing them farewell, and telling them to have good heart and to ride on till dark without halting.
Tom will give you good advice, till this day is over (after that your own luck must go with you and guide you): four miles along the Road you'll come upon a village, Bree under Bree-hill, with doors looking westward. There you'll find an old inn that is called The Prancing Pony. Barliman Butterbur is the worthy keeper. (Fog on the Barrow-downs)
Merry's 'people' visited from time to time.
‘I am sorry to take leave of Master Bombadil,’ said Sam. ‘He's a caution and no mistake. I reckon we may go a good deal further and see naught better, nor queerer. But I won't deny I'll be glad to see this Prancing Pony he spoke of. I hope it'll be like The Green Dragon away back-home! What sort of folk are they in Bree?’
There are hobbits in Bree,’ said Merry, ‘as well as Big Folk. I daresay it will be homelike enough. The Pony is a good inn by all accounts. My people ride out there now and again.’ (Fog on the Barrow-downs)
Bree-land was the only inhabited area in the region:
Bree was the chief village of the Bree-land, a small inhabited region, like an island in the empty lands round about Besides Bree itself, there was Staddle on the other side of the hill, Combe in a deep valley a little further eastward, and Archet on the edge of the Chetwood. Lying round Bree-hill and the villages was a small country of fields and tamed woodland only a few miles broad. (At the Sign of the Prancing Pony)
and Bree-lander Hobbits claimed to predate the Shire, and they were known to have mutual intercourse, mostly with Eastfarthing, which was only a day's ride away.
There were also many families of hobbits in the Bree-land and they claimed to be the oldest settlement of Hobbits in the world, one that was founded long before even the Brandywine was crossed and the Shire colonized. [...] The Bree-folk, Big and Little, did not themselves travel much; and the affairs of the four villages were their chief concern. Occasionally the Hobbits of Bree went as far as Buckland, or the Eastfarthing; but though their little land was not much further than a day's riding east of the Brandywine Bridge, the Hobbits of the Shire now seldom visited it. An occasional Bucklander or adventurous Took would come out to the Inn for a night or two, but even that was becoming less and less usual. [...] It was not yet forgotten that there had been a time when there was much coming and going between the Shire and Bree. There was Bree-blood in the Brandybucks by all accounts.(The Sign of the Prancing Pony)
From the second chapter, "The Shadow of the Past" (emphasis mine):
He lived alone, as Bilbo had done; but he had a good many friends [...] Frodo went tramping all over the Shire with them; but more often he wandered by himself, and to the amazement of sensible folk he was sometimes seen far from home walking in the hills and woods under the starlight. Merry and Pippin suspected that he visited the Elves at times, as Bilbo had done.
So we learn that Frodo travelled a lot, with his friends or even alone: he clearly gets to know the place very well. Also, he talks with the Elves (more on that later).
Frodo himself, after the first shock, found that being his own master and the Mr. Baggins of Bag End was rather pleasant. For some years he was quite happy and did not worry much about the future. But half unknown to himself the regret that he had not gone with Bilbo was steadily growing. He found himself wondering at times, especially in the autumn, about the wild lands, and strange visions of mountains that he had never seen came into his dreams. He began to say to himself: 'Perhaps I shall cross the River myself one day.' To which the other half of his mind always replied: 'Not yet.'
He starts thinking of the "wild lands" (outside of the Shire), and he's torn between leaving and staying at home; and even if he chooses not to leave, he still intends to do it at a later time. Even more: he doesn't generically think of "leaving", but specifically of "crossing the river" (the Brandywine/Baranduin), which is on the eastern side of the Shire, towards Bree. So even the direction he has on his mind is the one leading to Bree. This is after all the same direction that Bilbo had taken, which means a lot to him, as he regrets not leaving with him.
So it went on, until his forties were running out, and his fiftieth birthday was drawing near: fifty was a number that he felt was somehow significant (or ominous); it was at any rate at that age that adventure had suddenly befallen Bilbo. Frodo began to feel restless, and the old paths seemed too well-trodden. He looked at maps, and wondered what lay beyond their edges: maps made in the Shire showed mostly white spaces beyond its borders. He took to wandering further afield and more often by himself; and Merry and his other friends watched him anxiously. Often he was seen walking and talking with the strange wayfarers that began at this time to appear in the Shire.
Here we see that Frodo is growing tired of staying in the Shire, and he consults maps. And while it's true that "maps made in the Shire showed mostly white spaces beyond its borders", it's safe to assume that Bree, being the only town to the East of the Shire1, where several Hobbits live, is a known place, reported by all the maps. Bree isn't that far away after all; according to the map that comes with the book, from the Brandywine Bridge to Bree it's a bit more than 100 miles; as reported by Shamshiel's answer, "[Bree] was not much further than a day's riding east of the Brandywine Bridge"). So if one place outside of the Shire is known, that's Bree.
There were rumours of strange things happening in the world outside; and as Gandalf had not at that time appeared or sent any message for several years, Frodo gathered all the news he could. Elves, who seldom walked in the Shire, could now be seen passing westward through the woods in the evening, passing and not returning; but they were leaving Middle-earth and were no longer concerned with its troubles. There were, however, dwarves on the road in unusual numbers. The ancient East-West Road ran through the Shire to its end at the Grey Havens, and dwarves had always used it on their way to their mines in the Blue Mountains. They were the hobbits' chief source of news from distant parts - if they wanted any: as a rule dwarves said little and hobbits asked no more. But now Frodo often met strange dwarves of far countries, seeking refuge in the West. They were troubled, and some spoke in whispers of the Enemy and of the Land of Mordor.
Here we see that Frodo talks with "strange wayfarers" (actually mentioned in the previous paragraph), including Elves (as Merry and Pippin suspected in the firts paragraph I've quoted) and Dwarves. All these travellers are coming from the East (the Elves are "passing westward", and the Dwarves are "seeking refuge in the West"), so it's only natural that they stopped in Bree, even if only for a night, and that they told Frodo about it.
Frodo used to travel a lot, he was very interested in what was outside of the Shire, he wanted to go to the East (following Bilbo), he studied maps, he talked with several travellers coming from the East, and Bree is pretty much the only place to the East of the Shire1. Though he had never been to Bree before, he certainly knew very well where it was.
1 There were actually also Staddle, Combe, and Archet, but they are smaller and all close by, to the point that they are collectively known as "Bree-land".