The Science of Happiness at New York University is so popular, sometimes students who aren’t even registered for it sit in on the class.

“I’ve had students come up at the end of the semester and say, ‘Hey, I just want to let you know, I wasn’t enrolled in this class, I just really wanted to take it, so don’t be upset,’” said Daniel Lerner, who co-teaches the elective with Dr. Alan Schlechter, director of the Outpatient Child and Adolescent Psychiatry program at Bellevue Hospital.

Most of the undergrads sitting in the Stern School of Business auditorium each semester are there because a fellow NYU student told them to take it. That was the case for Kathryn Rafailov.

“I recommend it to everyone I know and tell them it’s recommended for a reason,” said the junior, who is currently taking the class. “I feel like every class is helpful and gives you something that you can actually use.”

For those who don’t manage to get a seat in the class — the largest elective at the school, with more than 450 students — the teachers have you covered. “U Thrive: How to Succeed in College (and Life)” ($16.99; out April 18) is essentially the Science of Happiness in book form.

Much like the class, it blends the teachers’ goofball humor with studies that show the importance of positive emotions, like meaning, purpose, choice and willpower, in order to actually make these the best four years of your life.

“College is more stressful than it’s ever been,” said Lerner, who has a master’s in applied positive psychology and has taught the class with Schlechter at NYU since fall 2012. “People have been suffering from stress and anxiety and related issues more than we’ve ever found.”

According to a 2016 report by the American College Health Association, more than half of undergraduate students reported feeling “overwhelming anxiety” within the past year. The conversation around mental health has also increased in recent years following a rash of suicides on campuses, including NYU’s.

NYU’s Child and Adolescent Mental Health Studies minor program created the Science of Happiness class “after a series of tragedies on the NYU campus,” Schlechter said. “The university really had to grapple with the idea of, how are we going to introduce mental health to the campus?”

With their blend of science and storytelling, Lerner and Schlechter’s twice-a-week classes have been compared to TED Talks. When not getting students to laugh or perk up with Pixar clips, they get them to listen. During a recent class on nutrition, a series of maps showing the increase in adult obesity in the United States drew audible gasps.

Readers of all ages might want to benefit from the Science of Happiness, though the book is geared toward undergrads and incorporates studies that focus primarily on college students, Lerner said, from demonstrating the benefits of eating breakfast on academic performance, to how friendships impact our well-being.

The Science of Happiness is a rare, but not exactly unheard of, class. Lerner pointed to similar courses offered at the University of Pennsylvania — where the father of positive psychology, Martin Seligman, taught — as well as Harvard.

“There are a ton of positive psychology classes around the country, but I don’t know any of them quite like ours, where we deal with how to both overcome challenges and how to thrive,” Schlechter said.

The two hope their new book becomes required reading for incoming freshmen.

“My dream is that this book lands on the pillow of every matriculated high school senior and incoming college student in the country,” Lerner said. “It can help make their entire experience a better one.”