  The production of J/$\psi$ mesons is studied in proton-lead collisions at the
centre-of-mass energy per nucleon pair $\sqrt{s_{\text{NN}}}=8.16$ TeV with the
LHCb detector at the LHC. The double differential cross-sections of prompt and
nonprompt J/$\psi$ production are measured as functions of the J/$\psi$
transverse momentum and rapidity in the nucleon-nucleon centre-of-mass frame.
Forward-to-backward ratios and nuclear modification factors are determined. The
results are compared with theoretical calculations based on collinear
factorisation using nuclear parton distribution functions, on the colour glass
condensate or on coherent energy loss models.
