I have a 2014 Honda. I bought the battery 2 years ago from the dealer?

Last night I went to start it and it made the machine gun sound, got a neighbor to jump me and it worked fine. This morning it also started first try, So, WHat happened last night and will it happen again? Do I need to take action so I won't get stranded?

One of the first things to do (because it's quick and easy) is check the sticker for date of manufacture on the battery. If it's older than three years, drive the car to an auto parts store or a Walmart auto center and get a free battery check. If necessary, replace the battery. If it's under warranty, ask the dealer where to get a replacement.

Yes! Take action. The "machine gun" sound prob your starter solenoid not getting enough currant. Load check your battery and check your charging system (alternator) output.

You haven't given us enough to go on. It could be the battery. It could also be something else, like some power drain in your electrical system. Or it could be something as simple as you having left the dome light on all night because you didn't quite get the door shut all the way.

Clean your battery terminals. It might be nothing more than some corrosion.

Have the battery load tested. Have the alternator tested. Have the starter tested. Make sure to close the doors when you park the car and don't leave any lights on.

A light may have stayed on and drained the battery over night.
If you have automatic headlights the drivers door jam triggers the timer to turn off the headlights. The door may have nut shut all the way or the drivers door jam switch may be going bad.
Wait for the headlights to turn off before walking away from the car.