Melt butter in a dutch oven or large sauté pan over medium low heat. Add onions and cook 20-30 minutes, until very soft and lightly golden.
Add brown sugar, vinegar, salt, pepper, and pepper flakes and stir well. Increase heat to medium-high to bring to a boil, then reduce back to medium to simmer for 10-15 minutes, until liquid is reduced and syrupy.
Transfer to jars, let cool to room temperature, and store in the refrigerator.
For canning
Set a water bath canner to boil about halfway through cooking the onion jam, to ensure water is hot enough.
Fill jars, leaving 1/4-inch headspace. Place lids and screw on rings fingertip tight, then carefully lower jars into the boiling water bath.
Process pint jars for 15 minutes, or half-pint jars for 10 minutes. Turn off heat and let jars rest in the canner for 5 minutes, then carefully remove and set on a towel-lined surface.
After 24 hours, check for seals, label, and store in a cool, dry place for up to 18 months.
Notes
If you like, add a sprig of rosemary or thyme during the cooking process. Be sure to remove before transferring the jam to jars.