To host a website for free with your own domain, you can use a combination of free cloud services like Vercel or Netlify and a free tier domain service like Freenom for domain registration. Here's a basic approach using Node.js and Vercel, which offers seamless deployment and a free tier for small projects.
Step 1: Set up a basic Node.js server
Create a simple Node.js application:
-
Initialize a New Node.js Project:
Create a new directory for your project and initialize it:
mkdir my-website
cd my-website
npm init -y
-
Install Express.js:
We'll use Express to set up a basic server. Install it using npm:
npm install express
-
Create a Simple Server:
Create a file named index.js and add the following server code:
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
// Serve static files from the "public" directory
app.use(express.static('public'));
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
-
Create a public Directory:
In the same directory, create a folder named public to store your static files (HTML, CSS, JS):
mkdir public
Then, add an index.html file inside the public directory if you want more details on your homepage.
Step 2: Deploy on Vercel
-
Install Vercel CLI:
If you don't already have it installed, you'll need to install the Vercel CLI:
npm install -g vercel
-
Deploy Your Project Using Vercel:
Inside your project directory, run:
vercel
Follow the prompts to link your repository and deploy your project. You might need to sign up or log in if you haven't used Vercel before.
-
Update Project Settings:
After deploying, Vercel will provide you with a default domain. You can connect your custom domain by going to your project's settings on the Vercel dashboard and adding your domain.
Step 3: Register a Free Domain
-
Register a Domain with Freenom:
Use Freenom or a similar service that offers free domain registration. Search for your desired domain and register it.
-
Update DNS Settings:
Go to the DNS settings for your domain and update the Name Servers to point to Vercel’s. Vercel will provide instructions on how to set this up in the settings of the custom domain section.
This setup guides you through deploying a simple Express.js application and making it available online for free using Vercel and a Freenom domain. Remember that while hosting and domains might be free, there might be limitations regarding bandwidth and storage. For larger projects, consider upgrading to a paid tier.