Development of nanocomposite based electrochemical sensors for detection of toxic chemicals describes an environmentally benign strategy for monitoring the health of ecosystem. Herein, we reported in situ preparation of graphitic carbon nitride (g‐C3N4) decorated Ag2S/NiFe2O4 nanocomposite sensor by facile precipitation method. The electrochemical studies demonstrated efficient electrocatalytic activity of ternary nanocomposite pasted glassy carbon electrode (g‐C3N4@Ag2S/NiFe2O4/GCE) for selective detection of formaldehyde. Moreover, fabricated sensor exhibit rapid amperometric response with excellent selectivity, remarkable sensitivity (1681 μA mmol L−1 cm−2) and lower detection limit (LOD: 1.63 μmol L−1). It is noteworthy to mention that sensor exhibits good operational and long‐term storage stability.