When you really think about it coffee is one of the most commonly and casually used drugs on the planet. It has been around since at least the 15th century and was first brewed in Arabia.
But what does coffee actually do to keep us awake?
Coffee introduces caffeine into your system which then blocks the receptors in the brain that usually receive adenosine which causes drowsiness / sleepiness. Additionally with the adenosine not being able to dock onto the receptors another response is triggered: your body produces adrenaline which keeps you alert because you basically enter a fight or flight mode.
With regular coffee consumption your brain actually changes and adapts to the regular caffeine delivery by changing the brain chemistry. Therefore withdrawal effects like a headache occur when caffeine ingestion suddenly stops. Unlike other addictive drugs these effects are fairly short term.
Coffee makes us feel good because it is able to tap into virtually every reward system our brain has to offer. Even though it essentially is a drug it is not considered as such by society since its side effects are rather light compared to so called hard drugs. Also its positive effects are much more prominent. It makes people feel better and boosts workers performance and office morale.