Hux followed a signal from a position sensor embedded in Kylo Ren's belt to find him, just in the nick of time.
According to the official Alan Dean Foster novelization, Hux takes a team of stormtroopers in a shuttle to Kylo's position, which he could triangulate from a position sensor that is apparently part of Kylo's belt:
A deep gully formed, separating her [Rey] from General Hux and the arriving troopers. Utilizing the tiny position sensor emplaced in Ren's belt, Hux had tracked him to this spot.
They carry Kylo into the shuttle, and off they go to safety.
This scene does not actually appear in the film.
According to the novelization, the rescue of Kylo Ren happens just before Chewie rescues Rey and Finn, and Finn had watched from across the crater as Hux's stormtroopers collected Ren — which means that Rey knows that Kylo survived (assuming his injuries weren't fatal).