How to stop my cookies going flat and hard?

I’ve been interested in baking for a while now and recently found a chocolate-chip cookie recipe. I went to make them today, and when I removed them from the oven they had spread out flat and gone hard and overly crispy. I buy cookies from the store and they’re obviously soft on the middle and crispy on the outside. How can I make mine like that?