Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140071

TypeError: res.sendStatus is not a function - Why do I keep getting this error?

$
0
0

I have been working in Node.js/Express in making a REST Api for the past several months. I'm running into this issue with my async function in my controller.js file. My callback function receives my request from the client but when I want to send a response I keep getting this TypeError: res.sendStatus is not a function Error.

Here's my code:

index.js

const express = require('express');
const { parseData } = require("../controllers/parse.controller");
const { checkFirebaseLogin } = require("../controllers/checkFirebaseLogin.controller");
var bodyParser = require('body-parser');
var router = express.Router();

router.use(bodyParser.json());  
router.use(bodyParser.urlencoded({ extended: false }));

router.post('/api/idToken', checkFirebaseLogin);
router.post('/', parseData);

module.exports = router

Here is my Controller.js file

checkFirebaseLogin.controller.js

const { checkUserLogin } = require("../services/checkUserLogin.service");

const checkFirebaseLogin = async (req, res) => {
    console.log("Checking on user token ...");
    const userToken = req.headers;

    try {
        var userUID = await checkUserLogin(userToken);
        console.log("Here's the repsonse:");
        console.log(userUID)
        res.sendStatus(201)
    } catch (error) {
        console.log("I'm here right before the error message on checking the user token")
        //console.log(error.message);
        console.log(error)
    }

};

module.exports = {
    checkFirebaseLogin
};

I am able to get the req.headers but when I try to send a response (via res.sendStatus(200)) back to the client I always get an error. Where I am going wrong?


Viewing all articles
Browse latest Browse all 140071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>