the date of receipt and acceptance should be inserted later Abstract. We have carried out a molecular survey of the Class 0 IM protostar NGC 7129 - FIRS 2 (hereafter FIRS 2) and the Herbig Be star LkH� 234 with the aim of studying the chemical evolution of the envelopes of intermediate-mass (IM) young stellar objects (YSOs). Both objects have similar luminosities (�500 L⊙) and are located in the same molecular cloud which minimizes the chemical differences due to different stellar masses or initial cloud conditions. Moreover, since they are located at the same distance, we have the same spatial resolution in both objects. A total of 17 molecular species (including rarer isotopes) have been observed in both objects and the structure of their envelopes and outflows is determined with unprecedent detail. Our results show that the protostellar envelopes are dispersed and warmed up during the evolution to become a pre-main sequence star. In fact, the envelope mass decreases by a factor >5 from FIRS 2 to LkH� 234, while the kinetic temperature increases from �13 K to 28 K. On the other hand, there is no molecular outflow associated with LkH� 234. The molecular outflow seems to stop before the star becomes visible. These physical changes strongly affect the chemistry of their envelopes. The N2H + and NH3 abundances seem to be quite similar in both objects. However, the H 13 CO + abundance is a factor of �3 lower in the densest part of FIRS 2 than in LkH� 234, very likely because of depletion. In contrast, the SiO abundance is larger by a factor of �100 in FIRS 2 than in LkH� 234. CS presents a complex behavior since its emission arises in different envelope components (outflow, cold envelope, hot core) and could also suffer from depletion. The CH3OH and H2CO column densities are very similar in FIRS 2 and LkH� 234 which implies that the beam averaged abundances are a factor >5 larger in LkH� 234 than in FIRS 2. The same case is found for the PDR tracers CN and HCN which have similar column densities in both objects. Finally, a complex behavior is found for the deuterated compounds. While the DCO + /H 13 CO + ratio decreases by a factor of �4 from FIRS 2 to LkH� 234, the D2CO/H2CO ratios is within a factor 1.5 in both objects. The detection of a warn CH3CN component with Tk>63 K shows the existence of a hot core in FIRS 2. Thus far, only a handful of hot cores have been detected in low and intermediate mass stars. Based on our results in FIRS 2 and LkH� 234, we propose some abundance ratios that can be used as chemical clocks for the envelopes of IM YSOs. The SiO/CS, CN/N2H + , HCN/N2H + , DCO + /HCO + and D2CO/DCO + ratios are good diagnostics of the protostellar evolutionary stage.