Literally, avoir le cafard means 'to have the cockroach'.
But really this informal expression means 'to be in a gloomy mood', 'to feel blue'.
Well, wouldn't you be, if you had cockroaches running around in your head? It's a fitting metaphor, because of the way that a bad mood can sneak into your mind and then take hold, just like cockroaches in a house.
So, if you want to express to someone in French that you're having a bad time of things you would say: J'ai le cafard ('I'm feeling down').
The Robert dictionary says that the word “cafard” may come from the Arabic word “kafir”, “with no religion”. One of the first meaning of “cafard” is : “Someone who only pretends to be a devout believer but is not, a hypocrite, a traitor".
It was the French poet Charles Baudelaire who popularized that meaning while writing Les Fleurs du mal in 1857.
Talking about the devil :
« Parfois il prend, sachant mon grand amour de l’Art,
La forme de la plus séduisante des femmes,
Et, sous de spécieux prétextes de cafard,
Accoutume ma lèvre à des philtres infâmes. »
English Translation :
Sometimes, knowing my deep love for Art, he assumes
The form of a most seductive woman,
And, with pretexts specious and hypocritical,
Accustoms my lips to infamous philtres.
Initially, Avoir le cafard described "having negativity in one's life", then became synonymous with "feeling depressed" – regardless of whether you actually have cockroaches in your house.
avoir un coup de cafard – to have a fit of depression
ça me donne le cafard – that depresses me
c’est à vous donner le cafard – it’s enough to depress you
sortir d’une période de cafard – to have just gone through a fit of depression