The song you're likely thinking of is "Midnight Special" by Creedence Clearwater Revival (1969). The track opens with a driving, chugging rhythm guitar pattern that unmistakably evokes a steam locomotive picking up speed—a sonic hallmark of John Fogerty's swamp-rock vision.
The train imagery continues lyrically, referencing the traditional folk song about a train's light shining on prisoners, symbolizing hope and freedom. CCR's version, on the album Willy and the Poor Boys, remains the definitive rock interpretation.