I work nights, and the most important thing is getting sleep during the day. I get at least six to eight hours every day, and I don’t have a problem, but it’s important to make sure that you have a good environment for sleep. Take the phone out of the bedroom, have dark curtains, have a bedtime routine that you follow, have a white-noise creator like a fan or some music to drown out any ambient noises from the outside (traffic, pedestrians, etc). Taking a mild sleep aid like benadryl or simply sleep is okay once in a while, but you don’t want to make a habit out of it. Also, sleeping with drugs isn’t as restful as regular sleep.
During your shift, don’t overdo it on the caffeine, and I’d stop the caffeine after about 5am or so (that’s usually when I switch to decaf) to make sure that you don’t have caffeine keeping you awake. If you want to knit, have a non-hypnotic project to work on, ie not just stockinette, to keep you awake. Also have other things to do that require the use of your mind, just in case you find yourself with time on your hands and nothing to do.
But don’t expect to just be doing nothing, Night Shifts can be busier than Day shifts in some places (like in hospitals, where I work). Welcome to the dark side! I love working nights and I hope you do too!