We present an investigation on the production of light dark photons by the nucleon bremsstrahlung processes in the core of neutron star. The dark photon is assumed to be a U (1) B−L gauge boson with a mass much below keV. We calculate the emission rate of dark photon produced by the nucleon bremsstrahlung in the degenerate nuclear matter. Assuming the APR equation of state for the neutron star with a canonical mass of 1.4 M , we find that the coupling e > 2.77 × 10 −11 T 10 9 K 2 has been excluded by the neutron star cooling. This gives a constraint of e < 8.4 × 10 −14 by using the observations on SGR 0418+5729. The emitted dark photon may convert to X-ray photons as it propagates radially outwards through the magnetosphere surrounding the neutron star. We exclude the dark photon interpretation for the X-ray excess from the M7 observations by taking into account the neutron star cooling constraints.