Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

451
Views
Cannot GET /api/courses/1 errror how to fix it
const express = require('express');


const app = express();

app.get('/',(req,res) =>{       // result shows on localhost:3000
    res.send('hello world');
});

app.get('/api/courses',(req,res) =>{    // result shows on localhost:3000/api/courses
    res.send(\[1,2,3\]);
});

app.get('/api/courses/:id',(req,res) =>{    // result does not show on localhost:3000/api/courses/1
    res.send(req.param.id);
});

//PORT


const port= process.env.PORT||3000;


app.listen(port,()=\>console.log(\``Listening to port ${port}...`\`));

I seem to be getting result for the first 2 get functions but not the ID, i get the following error Cannot GET /api/courses/1 how do i fix it ?

was expecting output of id as '1' to display

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You did have a syntax error in your console.log() line when starting the server: console.log(``Listening to port ${port}...\) is not valid JavaScript (this might have been just an editing error when you pasted your code here).

But most important, you are missing an s in param. It should be req.params.id.

Below code does work for me. I've tested it using Postman.

import express from "express";

const app = express();

app.get("/", (req, res) => {
  // result shows on localhost:3000

  res.send("hello world");
});

app.get("/api/courses", (req, res) => {
  // result shows on localhost:3000/api/courses

  res.send([1, 2, 3]);
});

app.get("/api/courses/:id", (req, res) => {
  // // result does not show on localhost:3000/api/courses/1 res.send(req.param.id);
  res.send(`This handler has received the value ${req.params.id} for ID`);
});

//PORT

const port = process.env.PORT || 3000;

app.listen(port, () => console.log(`Listening to port ${port}...`));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!