In this work, a N-doped CsTi2NbO7@g-C3N4 (NTCN) heterojunction nanocomposite was synthesized by a simple one-step calcination method. The as-prepared samples were characterized by means of X-ray diffraction patterns, scanning electron microscopy, high-angle annular dark-field scanning transmission electron microscopy, and Fourier transformed infrared spectroscopy. The results showed that g-C3N4 was formed both on the surface and within the interlayers of CsTi2NbO7, in which CsTi2NbO7 was in situ doped by nitrogen atoms to form N–CsTi2NbO7. The NTCN composite displayed higher electrocatalytic activity toward the detection of nitrite than pure CsTi2NbO7 and g-C3N4. The main reasons could be attributed to the synergistic effects of morphology engineering, N-doping, and layered heterojunction. The NTCN-based electrochemical sensor expressed a good linear relationship range from 0.0999 to 3.15 mmol/L with a detection limit of 2.63 × 10−5 mol/L. The good recovery, stability, and reproducibility of this biosensor showed the potential application in environmental monitoring.