This paper reports the measurement of J/psi meson production in proton proton (pp) and proton lead (pPb) collisions at a center-of-mass energy per nucleon pair of 5.02 TeV by the CMS experiment at the LW. The data samples used in the analysis correspond to integrated luminosities of 28 ph(-1) and 35 nb(-1) for pp and pPb collisions, respectively. Prompt and nonprompt J/psi mesons, the latter produced in the decay of B hadrons, are measured in their dilution decay channels, Differential cross sections are measured in the transverse momentum range of 2 < p(T) < 30 GeV/c, and center-of-mass rapidity ranges of vertical bar y(CM)vertical bar < 2.4 (pp) and -2.87 < y(CM) < 1.93 (pPb). The nuclear modification factor, R-pPb, is measured as a function of both p(T) and y(CM). Small modifications to the J/psi cross sections are observed in pPb relative to pp collisions. The ratio of J/psi production cross sections in p-going and Pb-going directions, R-FB, studied as functions of p(T) and y(CM), shows a significant decrease for increasing transverse energy deposited at large pseudorapidities. These results, which cover a wide kinematic range, provide new insight on the role of cold nuclear matter effects on prompt and nonprompt J/psi production.