This study investigates the photoexcitation and ionization of a nitrogen molecule under ultrafast (femtosecond/attosecond) laser pulse irradiation. The real-time and real-space time-dependent density functional (TDDFT) is applied to describe the electron dynamics during the linear and nonlinear electron-photon interactions. The calculations describe well the behavior of the ionization process, and the results of ionization rates show good correspondence with the experimental results. In addition, the effects of near-infrared femtosecond laser pulse trains and the selected extreme ultraviolet attosecond laser pulse trains on electron dynamics are discussed. Theoretical results show that pulse number, laser frequency, and pulse delay are the key parameters for the control of electron dynamics including the electron excitation, energy absorption, electron density, and electron density oscillation.