Peanut mildew can produce aflatoxin with strong toxicity. A nondestructive and rapid detection method of peanut mildew based on hyperspectral technology was proposed. Firstly, 600 Dabaisha peanuts purchased in the market were selected, and 200 peanuts were randomly selected for mildew treatment, while the remaining 400 peanuts were kept aseptically. After 30 days, the spectral images of all peanut samples were collected by using the Zhuoli Huanguang Hyperspectral Instrument and the SpaceView was used for black and white correction. Then the ROI of each peanut spectral image was extracted with ENVI5.1 software and the Mean spectral reflection value of the region was calculated to obtain the sample spectral data, the reflection curves of moldy peanuts and healthy peanuts were observed, and it was found that there were significant differences between 500nm-600nm, so the mold visualization of moldy peanuts was carried out within this interval. In order to eliminate the influence of non-quality factor information in the hyperspectral data, three spectral preprocessing methods were adopted to eliminate the noise in the original spectral data. XGBoost, LightGBM and RandomForest algorithms were run to model the characteristic bands and detect the moldy peanuts. In all models, the accuracy of the algorithm could reach 100%, the similarity indexes all reached 1, and the loss was all 0. In terms of FIT_TIME, XGBOOST had the best performance, only requiring 0.042s, which was significantly different from other algorithms. The results showed that XGBOOST model was the most suitable algorithm for detecting peanut mold. This study provides a strong theoretical basis and technical support for the monitoring and identification of healthy and moldy peanuts in peanut processing industry.