This module determines the root domain for any domain or sub domain. It takes into account that certain 'second level domains' exist, like '.co.uk' or 'com.au'.
npm i root-domain -S
const rootDomain = require('root-domain');
console.log(rootDomain('example.com')); // prints example.com
console.log(rootDomain('a.b.c.sub.example.com.au')); // print example.com.au
The domain name MUST NOT end with a '/'.
Use this module at your own risk.