adding any title cause stack overflow saying its spam i did’nt get my anwser thats why asking question please help urgentlly

POSTMAN CONTINOUSLY SHOWING SENDING REQUEST
postman

index.js
import express from "express";
import dotenv from "dotenv";
import { connectDB } from "./database/db.js"; // Ensure this aligns with your DB connection
import userRoutes from "./routes/user.js";

dotenv.config();

const app = express();

// Use middlewares
app.use(express.json());

// Define port
const port = process.env.PORT

// Basic route
app.get("/", (req, res) => {
  res.send("Server is working");
});


app.use("/api", userRoutes);
// Add additional routes if needed

// Start the server and connect to the database
app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
  connectDB(); // Ensure this is correctly implemented
});
controllers user.js

import { User } from '../models/User.js';
import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
import sendMail from '../middleware/sendMail.js';
import TryCatch from '../middleware/TryCatch.js';

// Register a new user
export const register = TryCatch(async (req, res) => {
  const { email, name, password } = req.body;

  // Check if the user already exists
  let user = await User.findOne({ email });

  if (user) 
    return res.status(400).json({
      message: "User already exists",
    });

  // Hash the user's password
  const hashPassword = await bcrypt.hash(password, 10);

  user = {
    name,
    email,
    password: hashPassword,
  };

  // Generate OTP and activation token
  const otp = Math.floor(Math.random() * 1000000);

  const activationToken = jwt.sign(
    {
      user,
      otp,
    },
    process.env.Activation_Secret,
    {
      expiresIn: '5m',
    }
  );

  const data = {
    name,
    otp,
  };

  // Send OTP email
  await sendMail(email, 'E-learning', data);

  res.status(200).json({
    message: 'OTP sent to your email',
    activationToken,
  });
});

// Verify user registration
export const verifyUser = TryCatch(async (req, res) => {
  const { otp, activationToken } = req.body;

  // Verify activation token
  const verify = jwt.verify(activationToken, process.env.Activation_Secret);

  if (!verify) 
    return res.status(400).json({
      message: 'OTP expired',
    });
  
  // Check OTP
  if (verify.otp !== otp) 
    return res.status(400).json({
      message: 'Wrong OTP',
    });

  // Create new user
  await User.create({
    name: verify.user.name,
    email: verify.user.email,
    password: verify.user.password,
  });

  res.json({
    message: 'User registered',
  });
});
routes user.js
import express from "express";
import { register, verifyUser } from '../controllers/user.js'; 

const router = express.Router();

router.post("/user/register", register);
router.post("/user/verify", verifyUser);

export default router;
db.js
import mongoose from "mongoose";

export const connectDB = async () => {
  try {
      await mongoose.connect(process.env.DB)
      console.log("database connected");
  } catch (error) {
    console.log(error);
  }
};

What I have tried so far:

Verified Server is Running:

The server starts and logs “Server is running on http://localhost:4000” and “database connected”.
Checked for Code Issues:

Ensured there are no syntax errors or unhandled exceptions in my code.
Increased Logging:

Added console logs in the controller to trace request handling.
Firewall and Port Issues:

Allowed Node.js through the Windows firewall.
Opened port 4000 in Windows firewall settings.
Tried disabling SSL certificate verification in Postman.
Used Different Clients:

Attempted requests via Postman, curl, and browser.
Received Cannot GET /api/user/register in the browser.

Postman and curl both resulted in ECONNRESET.
Curl Command:

Used the following curl command:
sh
Copy code
curl -X POST http://localhost:4000/api/user/register -H “Content-Type: application/json” -d “{“name”: “Anirudh”, “email”: “[email protected]”, “password”: “password”}”
Questions:

What could be causing the Cannot POST /api/user/register error?
Are there any specific configurations I might be missing in my setup?
Could the issue be related to the Windows firewall or network settings?
Any other suggestions to troubleshoot and resolve this issue?
Console Logs:

Server is running on http://localhost:4000
database connected
Received registration request { email: ‘[email protected]’, name: ‘Anirudh’, password: ‘password’ }
Any help or pointers would be greatly appreciated!

help me even tried thunder client

New contributor

Aniruddh tiwari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật