File photo of Adam "DJ A.M." Goldstein at the 2009 MusiCares Person of the Year gala in honor of Neil Diamond in Los Angeles

On the surface, DJ AM (a k a Adam Goldstein) had it all.

At his peak in the ’00s, he was a top-earning DJ, was spotted spinning at every A-list party around — and at one point, was even engaged to Nicole Richie. But, as the new excellent new documentary “As I AM: The Life and Times of DJ AM” shows, Goldstein had deep-seated demons that stayed with him his whole life — and eventually led to the 36-year-old star’s death via overdose in his Manhattan apartment in 2009.

The movie, which premieres at Tribeca Film Festival on Friday, charts AM’s life and zooms in on not only what he achieved but also the often-grim story behind his success. “It was intended to be more about the person than the star,” director Kevin Kerslake tells The Post. Here, five things we learned from the documentary:

He had a messed-up family life.

AM was born amid parental turmoil. Before he was conceived, his mother, Andrea Gross, came home and found her husband having sex with another man. She left, had an affair and got pregnant — but returned to her husband, leading him to believe that the child (AM) was his right up until birth. “A lot of the demons he was dealing with — especially in later life — came from family circumstances,” explains Kerslake. “Part of the deal I made with his mother in making this film was that we wouldn’t sugarcoat any of that.”

He was once a member of Crazy Town.

Back when rap metal was all the rage, AM was a member of the Los Angeles crew, providing scratches on their 1999 debut album, “Gift of Game,” which also featured “Butterfly,” their sole big hit.

He almost committed suicide in his early 20s.

Despite making a name for himself early in life in the hip-hop world, AM battled a severe crack addiction, which culminated in a suicide attempt — which failed only because the gun jammed.

AM signed up to do the MTV intervention reality show “Gone Too Far” in 2009 to help other addicts. But being up close and personal with drugs, as well as his own torment over surviving a 2008 plane crash alongside Blink 182’s Travis Barker, contributed to a descent back into usage. “He wanted to help other people out of the hole,” says Kerslake. “In a sense, he martyred himself with the show.”

He played a huge part in the current popularity of EDM.

Thanks to the way he popularized mash-ups, his big-money bookings in Las Vegas and his own club LAX (which he co-owned), DJ AM is a key factor in dance music’s dominance. “AM was the first rock-star DJ — there wasn’t anyone who had his skill set, and he’s one of the reasons that the culture is flourishing,” adds Kerslake.

It’s just a shame AM’s not here to see it.