The child's mum admitted to police she had snorted the class A drug through a straw which she then put in a drawer but later found her son holding it.
A court heard the woman was more concerned with shouting and swearing at social workers who went to her home in east Leeds rather than caring for the youngster.
Details of the incident were revealed as the woman was sentenced at Leeds Crown Court after pleading guilty to two offences of child neglect.
Matthew Harding, prosecuting, said the social workers went to the house after concerns were raised over the safety of the children.
Mr Harding said the social workers knocked on the front door but there was no answer despite crying coming from inside.
They found the five-year-old of the sofa complaining that his tummy hurt.
The social workers asked the defendant if she had taken the child to a doctor and she said she would arrange an appointment with her GP.
The social workers left to seek legal advice then returned later the same morning.
The prosecutor said they went to check on the boy and found him in bed holding a ball and crying.
The defendant was handed a letter informing her that child care proceedings were going to be taken against her.
She became verbally abusive, ripped up the letter and shouted: "You are not taking my f****** kids."
The youngster vomited three times and cried but she continued to be aggressive towards the social workers rather then caring for her son.
An ambulance was called as the social workers became increasingly concerned for the boy's welfare.
She refused to get into the ambulance and stayed at the property.
Urine samples taken from the boy at the hospital revealed traces of cocaine.
Hair samples were then taken from the youngster which revealed he had been exposed to the drug over a number of months.
Samples taken from the boy's brother also revealed he had been exposed to the class A drug.
Interim care orders were taken out and the children were placed in foster care.
Mr Harding said the boy's condition was not life-threatening, but added: "The fact that he was able to access cocaine and ingest some amount is of serious concern and could have been more life-threatening than it was."
The mum was interviewed and accepted that she had been a cocaine user for around two years.
She said she used the drug when she was depressed and took it when the children were in bed.
She told police she snorted four lines of the drug the day before her son became ill.
The defendant said she used a straw to snort the drug before putting it in a drawer but later found her son holding it.
She said her children were able to get onto kitchen surfaces but she cleaned them regularly.
Asked if she thought her behaviour was reckless, she replied: "Careless I would say. Me being stupid. I would never hurt my children."
The court heard the children no longer live with the defendant and will not be returned to her.
Mark Foley, mitigating, said the woman had changed her life since the incident and had not committed any further offences.
She was given a ten-month prison sentence, suspended for 18 months, and ordered to complete 20 rehabilitation activity requirement days.
Sentencing, Judge Robin Mairs said: "In essence, you put your needs above theirs in a significant and potentially dangerous way. You let those boys down
"While your five-year-old son was pale and repeatedly vomiting, your attention was focused on the social workers as you screamed and swore at them.
"Any decent mother would have been concerned for her children. You, it seemed, were concerned your yourself.
"The impact of this offending could have been catastrophic."