- You have an existing linux cpanel hosting (shared/dedicated).
- You have hosted your nodejs application on some other hosting provider such as heroku/clever-cloud.
- You want the contents should be served from the nodejs hosting.
- You want the email accounts which you have been using should work as it is.
- You have an existing domain name registered say via Godaddy, example: www.mydomainname.com
- Your nodejs application has a domain say mynodewebsite.herokuapp.com
- Your Name Server for www.mydomainname.com points to your existing cpanel hosting say ns1.cpanelhosting.com
Work to be done:
- Add your domain name in the alias of your project in nodejs hosting , i.e. add www.mydomainname.com as alias in your heroku account for the mynodewebsite.herokuapp.com
- The DNS of www.mydomainname.com will have to be changed from your cpanel hosting (not from your domain registrar eg: godaddy)
For the first part i.e. adding custom domain to your nodejs app, steps are really easy.
For Heroku hosting:
- Goto your dashboard.
- Click on the application which you want to add custom domain.
- Click on settings on top right.
- Scroll down a bit, Click on Edit in the Custom Domain.
- Add both mydomainname.com and www.mydomainname.com over there
- Click on Save, Thats It!
What do you need for this?
- The ip address of the nodejs hosting website on which it resides.
- Your main domain name.
To get the ip address of your nodejs hosting, try to ping it from your console/command prompt.
Alternatively you can take the help of websites which would give you the ip address of any website, for eg https://www.site24x7.com/find-ip-address-of-web-site.html
Just put in the url of your nodejs app url say mynodewebsite.herokuapp.com and it will show you the ip address of it. Copy that ip address to clipboard!
Steps to change your current DNS for main domain:
- Log into your Cpanel hosting, usually via cpanel.mydomainname.com by providing login credentials.
- Scroll down till you find heading as DOMAINS.
- Click on Advance DNS Zone Editor.
- Select the domain name from the drop down over there.
- Scroll down to the Zone File Records.
- Now you have to change 2 things over here, the Type A record and the cname record for your main domain.
- Click on edit in the row where its shows your main domain eg: mydomainname.com.
- You will have to change the ip address listed over there with the one which you just copied for your nodejs hosting.
- Save the record and scroll down where it says www.mydomainname.com .
- You will have to change it CNAME for this record from www.mydomainname.com to mynodewebsite.herokuapp.com