Point A and MX records to different servers

The more I read the more confused I get, so please advise...

I bought a godaddy domain.

I have 2 servers, and I want the following...

  • Justhost (Email)
  • Digital Ocean (Web server for app)

How can I receive emails on Justhost, but run the app on Digital Ocean?

  • Domain should point to which host's nameservers?
  • Where do I setup the A record and where do I point it?
  • Where do I setup the MX record and where do I point it?

DNS, email and web pages are all different services and can all three be hosted on the same or different service providers. If you are confused, you could think them through an analogy:

  • DNS is like a phone book having information on all the people with their contact information.
  • IP addresses on A records are like phone numbers. You could e.g. have one for your landline, one for your gsm, one for work etc.
  • Email service is like a fax. You can tell you have a email service through MX records, but eventually it's handled by servers with IP addresses. Likewise, a fax machine has a phone number: there's just a mention on the phone book telling it's not a normal number someone would answer.
    • If you point your example.com MX to a different domain mail.example.net it's like telling you don't have an own fax number, but faxes to you could be send to a fax machine at your workplace.

Now, neither the phone company handling your gsm nor your fax line doesn't have to maintain a phone directory having your numbers, although they both could. Also, anyone already knowing your number can contact you; the service exists to publish this information. The same applies to DNS.