Can I use ivermectin as heartworm meds for my dog instead of

  If so, how do I know how much to give my dog and where can I buy some online?
Ivermectin is the generic version of heartguard. Both are prescribed by the vet and I believe the vet can "allow substitutions" ( at least that is what is true in human medicine ". So the answer is yes under the guidance of your vet.
Be aware, some breeds of dog react badly to Ivermectin:

"Dogs with a Genetic Sensitivity to Ivermectin

Breeds which may possess a genetic sensitivity to ivermectin are Collies, Shetland Sheepdogs and Old English Sheepdogs, although genetic sensitivities have been seen in individuals outside of these breeds as well. A blood test which detects the genetic mutation responsible for the ivermectin sensitivity is available and may be advisable for high-risk dogs before administration of high dosages of ivermectin. Heartworm preventive dosages of ivermectin are normally low enough to be safe for these high-risk dogs.

Symptoms such as uncoordination and dilated pupils are of particular concern and can lead to death if treatment is not sought immediately. "
Are you asking if you can buy injectable ivermectin and give it to your dog monthly instead of the chews? Ranchers and farmers have done this for decades. This is partly where all the problems with ivermectin and collies comes in. Talk to your vet if you have interest in doing this. It can be very dangerous.
PLEASE, call your vet and ask IF THIS IS SAFE. My neighbor poisoned her dog (killed it) with Ivermectin. You must know IF it is safe and IF it is, then you must know EXACTLY HOW MUCH TO GIVE and you must be able to MEASURE IT WITHOUT ABSOLUTE ACCURACY.
Heartgard pretty much is ivermectin.