What not to do? Don't devalue what the person who's been telling your situation feels, don't try to take out suicidal ideas, don't judge or question what he says, don't give improvised advice, don't make promises he can't keep.
What to do? According to the research, asking and talking about the topic reduces the risk of suicide and as the emotional situation is talked about, it relaxes, so ask about your feelings and suicidal thoughts without fear, let it calmly express what counts, listen, do not fear the silences that may arise during the conversation, try to empathize and understand the reasons why you want to die.
For those who have these feelings and thoughts it is not easy to talk about it, therefore listen and not leave it alone, make it clear that it is there for him.
And the next step, of course, is to offer professional help, to go to the available media and phones.
According to the psychologist, the thoughts of suicide take approximately 90 minutes on average until it takes action. So it's important not to leave that person alone and talk quiet.
Paul R. Coca gives instructions in this thread. The psychologist has two books written about suicide prevention.