I have implemented a basic code for my backend. And I want to test my API route however every time I try to test it on postman or insomnia I always get and error 404 Not found. However my server is running since I am getting a message to my console confirming that. It is just my route is not working when I make a post request to Postman and Insomnia Here is my code for auth route.

the file path is C:UsersusersubsAppbackendroutesauth.route.js

`import express from "express";
import { registerUser } from "../controllers/auth.controller.js";

const router = express.Router();

router.post("/register", registerUser)

export default router;`

and this is my auth.controller.js

`import NewUser from "../models/NewUser.js";
import bcrypt from "bcrypt";
import catchAsyncErrors from "../utils/catchAsyncErrors.js";

export const registerUser = catchAsyncErrors(async (req, res, next) => {
    const { username, email, citizenship, academicQualification, password, confirmPassword } = req.body;
    try {
      // Check if the user already exists based on the email
      const existingUser = await NewUser.findOne({ email });
      if (existingUser) {
        return res.status(400).json({ success: false, message: "User already exists" });
      // Check if the password and confirmPassword match
      if (password !== confirmPassword) {
        return res.status(400).json({ success: false, message: "Passwords do not match" });
      // Hash the password before saving the user
      const hashedPassword = await bcrypt.hash(password, 10);
      // Create a new user instance
      const newUser = new NewUser({
        password: hashedPassword, // Save the hashed password
      // Save the new user to the database
      await newUser.save();
      res.status(201).json({message: "User created Succesfully!"});
      // Send token for authentication
      //sendToken(newUser, 201, res); // Sends token in the response
    } catch (error) {
      // Handle errors
      res.status(500).json({ success: false, message: "Server Error" });

I wanna know what might be the reason why I am getting an error 404 message. Any help would be greatly appreciated

I tried doing an HTTP POST request on insomia like this
localhost:5000/register and then I tried

and both are giving me 404 error NOT FOUND

New contributor

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