It is very important to detect heavy metal ions in coal mine wastewater. In this work, we developed a simple electrospinning and carbonization method to prepare nitrogen-doped carbon nanofibres based on ZIF-8 metal-organic nanoparticles. ZIF-8/polyacrylonitrile was prepared by electrospinning and then heat-treated in a nitrogen atmosphere. Then, the obtained material was treated with hydrochloric acid to remove residual zinc impurities. Carbon nanofibres were prepared and applied to modify the surface of an electrode for the electrochemical detection of Cd(II) and Pb(II). According to the experimental results, glassy carbon electrodes modified with nitrogen-doped carbon nanofibres showed good linear correlation, and the detection limits were 1.11 mu g/L and 0.72 mu g/L for Cd(II) and Pb(II) ions, respectively.