From Truman Capote to Jonathan Lethem by way of H P Lovecraft, Norman Mailer and Jonathan Safran Foer, Brooklyn holds an uncanny appeal for writers. Back in the 1940s, W H Auden shacked up in a commune in Brooklyn Heights with Benjamin Britten, Carson McCullers, Jane and Paul Bowles, Gypsy Rose Lee (the only one to pay her rent on time) and Klaus and Golo, sons of Thomas Mann. Capote wrote In Cold Blood and Breakfast at Tiffany's from a brownstone on Willow Street, and Hart Crane was inspired to begin composing his modernist epic The Bridge in an apartment overlooking the East River.
The borough dipped out of favour for a while (in the heady Manhattan era of Jay McInerney and Brett Easton Ellis, no one would be seen dead crossing the bridge), but these days Boerum Hill and Park Slope are, as Lethem put it, "repulsive with novelists" once again. Among the Pulitzer prizewinners and New Yorker stalwarts who live here are Jhumpa Lahiri, Paul Auster, Rick Moody, Jennifer Egan, Teju Cole, Colson Whitehead and Nicole Krauss. Even Martin Amis has got in on the act, buying a $2.5m brownstone in Cobble Hill late last year. And that's just the ones you've heard of.
Everyone in Brooklyn seems to be writing something. In self-defence, cafés have taken to posting stern "No laptops" signs to ward off the drifters who hog the power points, stretching a Stumptown single-origin espresso into hours. For those more self-consciously serious about their art, there's the Brooklyn Writers Space, which offers a desk, a chair and a lamp in various convivial lofts in return for three heavyweight references and $330 a quarter. A proselytising friend promises that it's worth every cent because the organisers, on request, will restrict your internet access and keep you geed up on free coffee, two sure-fire passports to productivity.
It is easy to imagine Brooklyn as the hipper-than-thou twin of Shoreditch in London. But although the Williamsburg neighbourhood does boast a dazzling array of civil war beards, Barbours and black-framed specs, there's an appealing whirr of industry about the borough that goes well beyond the cutely retro. In a way, it mimics the "locavore" trend in food that has led restaurants and markets to near-fetishise local enterprise and produce. Two of the best literary magazines launched in recent years - n+1 and the beguilingly strange Cabinet - are based here (the art mag Bomb is also a resident). All are deeply engaged with their readership, hosting frequent and sometimes slightly alarming events. I was particularly taken by the notion of Cabinet's Ugly Feelings: a night in celebration of the darker realms of human nature, featuring critics examining failure, humiliation and cruelty. "Fear not," says the invitation, "it's also a book party!"
This knack for making reading sociable also serves the independent bookshops. At BookCourt there are free events almost every night, ranging from performances by obscure local poets to a barnstorming appearance by Michael Moore, fresh from the temporary autonomous zone of the Occupy Wall Street protest and accompanied by three bulky bodyguards, testament to the death threats he receives.
An even bigger crowd spilled out for the novelist Jonathan Ames, who was hosting the premiere for season three of his magnificently droll spoof detective show, HBO's Bored to Death, in which a fictional Jonathan Ames solves crimes in Brooklyn while, yep, writing novels. Much to the delight of the audience, the opening scene was set at a reading at none other than BookCourt (on reflection, "locavore" might not quite capture the self-devouring aspects of the whole scene).
The pinnacle of these intellectual shindigs is undoubtedly the annual Brooklyn Book Festival, the largest literary event in New York, for which Columbus Park is transformed into something resembling a bookish souk. The stalls - nearly 200 of them - are manned by a bewildering miscellany of literary magazines, small presses and collectives, and churches and colleges are pressed into service as venues. This year, there were snaking queues for Foer and Joyce Carol Oates, who looked innocent as a librarian until she started to read about a battered child forced to identify her mother's dead body. Edmund White talked urban walking with Teju Cole, author of the much-feted Open City. And wandering across the square, I was struck by the edifying spectacle of the former US poet laureate Mark Strand booming his immortal words "all testicles, even the most forthright and gifted, swing dreamily among the clouds like little chandeliers" across the steps of Borough Hall.
It's nothing like any literary festival I've ever attended in the UK, not least because all the events are free. Faced with such a diverse and diverted crowd, I felt I might have stumbled into some dream republic of the reader, where books regain their ground by being made and consumed in gleeful conviviality. There is a postscript, though: Lethem, long the borough's favourite literary son, now lives in Claremont, southern California.
Olivia Laing's "To the River" is published by Canongate (£16.99)