2002 Nissan Pathfinder - Had the shakes, but it went away. Cause?

I recently just purchased a 02 Nissan pathfinder se. I was driving down the road and it started to have a rough idol and a shack. The check engine light came on so I pulled over. I shut the car off and cranked it back up and it stopped. I got in it the next morning and drove it to the doctors office and it done the same thing. On the way back home it didn’t do it all. Does anyone have any advice to what the issue could be? Thank you

We need the codes that were set to make any guesses. In most places, auto parts stores will read them for free.