The molecular formula of diazomethane is CH₂N₂, and the main reason for its instability is precisely the fact that it can very easily evolve nitrogen, as nitrogen's triple bond is one of the strongest covalent bonds in nature, and the energy released in its formation is more than enough to compensate the energy lost in the breaking of C-N bonds. The Lewis structure of diazomethane with the formal charges is attached below.
To obtain the molecular formula of diazomethane, we can imagine that we have 100 g of it. Now we can calculate the number of moles (n) for each of the elements, using their respective masses (m) and molar masses (M = 12 g/mol for carbon, 1 g/mol for hydrogen, and 14 g/mol for nitrogen):
n = m/M
n(C) = 28.57 g / 12 g/mol
n(C) = 2.38 mol
n(H) = 4.80 g / 1 g/mol
n(H) = 4.80 mol
n(N) = 66.64 g / 14 g/mol
n(N) = 4.76 mol
We now divide each of these numbers with the smallest of them (2.38) to calculate the molar ratio of the elements:
carbon: 2.38 / 2.38 = 1
hydrogen: 4.80 / 2.38 = 2
nitrogen: 4.76 / 2.38 = 2
Now we use these numbers to get the empirical formula of diazomethane: CH₂N₂.
The molar mass of the empirical formula is:
12 g/mol + 2 * 1 g/mol + 2 * 14 g/mol = 42 g/mol
Since this value is equal to the molar mass given to us, that means that CH₂N₂ is also the molecular formula of diazomethane.