App.get is not working in express

I use nodejs and express, and before now I always used post requests (app.post) which works as they should. But now I need to use a get request, and app.get is just not working. Nothing is loaded and the function on the server will not run (nothing is console.logged). Any idea what might be wrong?

The url I have tried is: http://localhost:3000/hello, I also tried http://localhost:3000/api/hello.

Here is what I have:

 require('dotenv').config()
    const express = require('express');
    const bodyParser = require('body-parser');
    const cookieParser = require('cookie-parser')
    const app = express();
    const port = process.env.PORT || 5000;
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(cookieParser())
    
// Get dont work:
    app.get('/api/hello', (req, res) => {
      console.log("Hello world")
      res.send('hello world')
    })

//But post works:
app.post('/api/hello', (req, res) => {
console.log("Hello world")
res.send('hello world')
})

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.