So an over-the-counter medication called melatonin is commonly used to treat insomnia, especially if it's sleep onset insomnia. Melatonin is a hormone that's secreted by our own body during bedtime and it helps with the sleep onset process. Taking supplemental melatonin will help you fall asleep but not stay asleep.
Now, it is also used to help treat circadian rhythm disorders so the time that you should be taking melatonin should be set by your physician whether you should take it an hour before bedtime or a few hours before bedtime. Some common side effects include daytime drowsiness and nightmares. Now, as we age our own melatonin production does decrease, so the use of supplemental melatonin will be helpful in those cases. It is not habit forming and you will not become dependent on the use of melatonin to help you sleep at night. But if you are using it long term, you should talk to your doctor about what may be causing your insomnia.
Melatonin is not habit forming but if you're finding that you have to use this for a long period of time to help you fall asleep then you should discuss with your doctor what might be the cause of your insomnia.