App.get is not working in express

I use nodejs and express, and before now I always used post requests ( 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:

    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.urlencoded({ extended: true }));
// Get dont work:
    app.get('/api/hello', (req, res) => {
      console.log("Hello world")
      res.send('hello world')

//But post works:'/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.