When a magnet is placed in a magnetic field it aligns itself along the field lines with the North Pole in the direction of the magnetic field.
On the surface of earth a magnetic field exists due to the contents of the earth making it behave like a magnet. Because of this a magnetic needle is used to find the direction on the surface of the earth.