Build a Next.js Website With Custom Domain in 10 Minutes

Joel Masters
Jan 27 · 4 min read
Photo by Ferenc Almasi on Unsplash

In this tutorial, we’re going to use create-next-app, Github, Netlify, and namescheap to deploy a Next.js static website with a custom domain name.

Next.js is a “production ready” library that uses React, with added benefits such as server-side rendering and routing out of the box. For more information, check out nextjs.org.

There are certainly other options for domain name registration and site hosting, but Namescheap provides the least expensive domains I’ve found, is easy to work with, and also comes with whoIs privacy protection for free (so you won’t be spammed with calls and emails when you register a new domain). Vercel is a very easy hosting platform.

Note: this method applies only to static sites generated with Next.js. Dynamic sites will require a node.js hosted backend.

STEP 1 OF 5: Create your app

In the terminal, type:

npx create-next-app my-awesome-app
cd my-awesome-app

IMPORTANT: In the package.json file, change the "build" command to "next build && next export"

STEP 2 OF 5: Push your app to GitHub

In GitHub, click on the “New” button in the top left:

Type the name of the app, and click the “create repository” button at the bottom of the screen:

Copy the code to push your existing repository from the command line:

Paste the code into the terminal to upload your code.

STEP 3 OF 5: Set up Netlify for hosting

Click on “New site from Git”

On the next screen, select “GitHub”

On the next screen, scroll down to find your GitHub repo for the app:

Then, on the next screen click “Deploy site”

For the “Build command” type yarn build, and for the “Publish directory” type out/

Next, click on “Domain settings”

Next, click on “Add custom domain”

Type in your domain and click verify

Then click “Yes, add domain”

Back on the Domain Settings screen, copy the .app link. You’ll use this later after you register the custom domain.

STEP 4 OF 5: Register your custom domain name at Namescheap

After your purchase is complete, go into your Dashboard, and find the domain name you want to transfer, and click the “MANAGE” button

Next, click on “Advanced DNS”

Click on “Add New Record”

Scroll down to CNAME and click

For the “Host” type “www”, and for the “Value” paste your .app link from Netlify. Hit the green check mark and you are good to go.

STEP 5 OF 5: Add your domain to Netlify

Head on over to your new site and start customizing it :). When you push to your GitHub repo your site will automatically update.

Thanks for reading.

If you created a webapp using this method, I’d love to know! Please leave a comment below.

Note: the namescheap link is an affiliate link. I use namescheap for all of my personal websites as I’ve found them to have the best and cheapest services. Feel free to go directly to their website instead.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Joel Masters

Written by

Creator of Goalsmash.net. Help others achieve their goals. Get paid.

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.