The standard procedure to do the wavelength calibration in spectroscopy is take an spectrum of a lamp of rarefied gases, which have a lots of emission lines. This procedure can be done in the optical as well in the NIR. The lamp spectrum is used to fit a dispersion function that will be applied to the science spectrum.
Alternativaly, in the NIR, is possible use the sky lines. The NIR there is a plenty of sky emission lines that can be used to perform the wavelength calibration.
In order to have a good match between sky exposures and science, an extraction with the same aperture is done for both. One of the advantages of this method is that each frame has their own spectrum of calibration.