Diazomethane, CH2N2, is a yellow, poisonous, potentially explosive compound, which is a gas at room temperature. The structure of diazomethane is explained using three resonance forms.
Conversion of carboxylic acids to methyl esters
Carboxylic acids react with diazomethane to produce methyl esters. Because of the high reactivity of diazomethane, it is produced in-situ and then immediately reacted with the carboxylic acid to produce the methyl ester.
The first step of the mechanism is a simple acid-base reaction to deprotonate the carboxylic acid. The carboxylate is then the nucleophile of an SN2 reaction with protonated diazomethane to produce the methyl ester with nitrogen gas as a leaving group. It is important to keep reaction vessels vented when gases are produced to avoid explosions.