Context. X-ray spectra of accreting pulsars are generally observed to vary with their X-ray luminosity. In particular, the hardness of the X-ray continuum is found to depend on luminosity. In a few sources, the correlation between the energy of the cyclotron resonance scattering feature (CRSF) and the luminosity is clear. Different types (signs) of the correlation are believed to reflect different accretion modes. Aims. We analyse two NuSTAR observations of the transient accreting pulsar Cep X-4 during its 2014 outburst. Our analysis is focused on a detailed investigation of the dependence of the CRSF energy and of the spectral hardness on X-ray luminosity, especially on short timescales. Methods. To investigate the spectral changes as a function of luminosity within each of the two observations, we used the intrinsic variability of the source on the timescale of individual pulse cycles (tens of seconds) , the so-called pulse-to-pulse variability. Results. We find that the NuSTAR spectrum of Cep X-4 contains two CRSFs: the fundamental line at~30 keV and its harmonic at~55 keV. We find for the first time that the energy of the fundamental CRSF increases and the continuum becomes harder with increasing X-ray luminosity not only between the two observations, that is, on the long timescale, but also within an individual observation, on the timescale of a few tens of seconds. We investigate these dependencies in detail including their non-linearity. We discuss a possible physical interpretation of the observed behaviour in the frame of a simple one-dimensional model of the polar emitting region with a collisionless shock formed in the infalling plasma near the neutron star surface. With this model, we are able to reproduce the observed variations of the continuum hardness ratio and of the CRSF energy with luminosity.