The worst thing about working graveyard shift is those hours when you are too sleepy to stay awake. Usually, the best solution is to make sure you have a job with enough work to keep you busy and enough toys to play with when bored.
Drinking coffee is all well and good, and I advocate this method. However, it is a diuretic, so drinking lots of water is a Good Thing, too. Tea has a better caffeine content that is released into your system at a slower rate than coffee.
Taking a walk every couple of hours is also good, as is having a co-worker to go on the walks with and bitch about work and share life experiences.
Nothing helps you get recharged when feeling drowsy than some good old tunes played loud! From industrial, to soul, to classical, expand your musical horizons, dance around the office/workspace, sing at the top of your lungs!
Utilizing crystal meth is something I experienced for two years, and I only recomend this if you have some sort of self-control and a cheap dealer. Otherwise, you will spend more money than you earn on it, and enter the realm of substance abuse outside the workspace.
Contructive use of deadtime is a must for staying awake. Learn a new program, a new machine, a new language, a new craft. Read many books and take notes from them. Push the photocopy machine to its limits. Practice card tricks and origami folds. Create, instigate, and promote imaginative endeavors. This is the key for staying awake in mind, body and soul in the workplace, on any shift.
Your job. It doesn't have to be a waste of your time.