Why GET request is not working in Node.js?

 const express = require('express');
 const mongoose = require ("mongoose");
 const app = express();
 const Student = require('../models/students');
 const PORT = process.env.PORT || 3000;
 const cors = require('cors');

 mongoose.connect(process.env.MONGO_URL, {
   useCreateIndex: true,
   useNewUrlParser: true,
   useUnifiedTopology: true,
   useFindAndModify: false
 }).then(() => {
    console.log("Connection is Successful");
 }).catch((e) => {
    console.log("No Connection");

 app.get("/studentData", async( req,res ) => {
       const getStudentsData = await Student.find();

 app.listen(PORT, () => {
 console.log(`Connection is setup at ${PORT}`);

Angular Code

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment'

   providedIn: 'root'
export class RestoService {

constructor(private http: HttpClient) { }

 readonly baseUrl = 'https://mean-curd-app.herokuapp.com';

 readonly url = '/studentData';

    return this.http.get(`${this.baseUrl}${this.url}`)

It’s working on localhost 3000 but when I host this MEAN stack app on Heroku then I got error msg which is status code 304. Connection is successful but something is wrong that’s why I got this error msg.

GitHub Source Code Link : https://github.com/SwapnilVedpathak-sv/mean-stack-application
Heroku Hosted Link : https://mean-curd-app.herokuapp.com

1 thought on “Why GET request is not working in Node.js?”

  1. There’s nothing wrong here. A 304 is not an error. It is how a web server set up for efficiency works. When a cooperating client asks for the same resource they’ve previously asked for in a "conditional GET request" and that resource has not changed since they previously cached it, then the server sends them a 304. The client can then use their cached version.

    For further info see this description on MDN.

    The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource. This happens when the request method is safe, like a GET or a HEAD request, or when the request is conditional and uses a If-None-Match or a If-Modified-Since header.


Leave a Comment