MERN

⌘K
  1. Home
  2. Docs
  3. MERN
  4. simple website

simple website

Folder Stracture

simple-website/
├── public/
│   ├── home.html
│   ├── about.html
│   └── contact.html
├── server.js
└── package.json

package.json

{
  "name": "simplewebsite",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "node main.js"


  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

main.js

const http = require('http');
const fs = require('fs');

const server = http.createServer((req, res) => {
    if (req.url === '/') {
        let data = fs.readFileSync('public/home.html', 'utf-8');
        res.end(data);
    } else if (req.url === '/about') {
        let data = fs.readFileSync('public/about.html', 'utf-8');
        res.end(data);
    } else if (req.url === '/contact') {
        let data = fs.readFileSync('public/contact.html', 'utf-8');
        res.end(data);
    } else {
        res.writeHead(404, { 'Content-Type': 'text/html' });
        res.end('<h1>404 Not Found</h1>');
    }
});

server.listen(8000, () => {
    console.log('Server is running on port ' + 8000);
});

home.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>

    <h1> Home </h1>
</body>
</html>

about.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>

    <h1> About </h1>
</body>
</html>

contact.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/contact">Contact</a></li>
    </ul>

    <h1> Contact </h1>
</body>
</html>

প্রজেক্ট ফোল্ডারে গিয়ে কমান্ড টি রান করি

npm start 

How can we help?