how to solve 404 issue in nodejs express

241 views Asked by At

I'm using vs code to develop my project using node.js. The problem is that API is not working when I run in postman and insomania the following error is given below:

Error 404

::ffff:127.0.0.1 - - [19/Oct/2022:04:07:36 +0000] "GET /api/prayer/create HTTP/1.1" 404 57 "-" "insomnia/2022.6.0"

Router code

const { Router } = require('express');
const prayerControllor = require('../controllers/prayer.controller');

const { celebrate, Joi } = require('celebrate');

module.exports = function (app) {

    const route = Router();
    app.use('/prayer', route);

    route.post('/create', celebrate({
        body: {
            prayerName: Joi.string().required(),
            iqamatTime: Joi.string().required(),
            namasTime: Joi.string().required(),

        }
    }), prayerControllor.createPrayer);
    route.patch('/update/:id', prayerControllor.updatePrayer);
    route.get('/get/:id', prayerControllor.getPrayer);
}
1

There are 1 answers

0
Karan Singla On

Ideally, I would need to look at more code to understand hour your routes are configured as from where '/api' path is coming.

Most likely issue is that you are trying GET call whereas your route is configured as POST.