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

172
Views
Node API - Cannot GET /url

I know there are several version of this but I can't seem to find a solution for mine. My server doesn't seem to see all routes in my routes file. It only matches the first one.

index.js

import express from 'express'
import mongoose from 'mongoose'
import dotenv from "dotenv";

import tweetRoutes from "./src/routes/tweetRoutes.js";

dotenv.config();

const app = express();
const PORT = process.env.PORT || 5000;

app.use(express.json());

// Routes
app.use("/api/tweets", tweetRoutes);

// DB connection
mongoose.connect(process.env.DB_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});
mongoose.connection.on("connected", () =>
    console.log("DB Connection Established!")
);


// Server
app.listen(PORT, () => console.log(`Server listening on: ${PORT}`))

tweetRoutes.js

import { Router } from 'express'
import {
    createTweet,
    fetchTweets,
    fetchTweet,
    updateTweet,
    deleteTweet,
} from "../controller/tweetController.js";

const router = Router();

router.get("/", fetchTweets);
router.get("/:id", fetchTweet);
router.post("/create-tweet", createTweet);
router.patch("/:id", updateTweet); // Not working
router.delete("/:id", deleteTweet); // Not working

export default router;

In this case, the only route accessible is the first one, fetchTweets. Even when I pass an ID param to get a single tweet using the fetchTweet route, it routes to the first route. The other routes return a 404.

What could I be doing wrong? Any help is highly appreciated.

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

0

Thank you for providing the url you used to test the fetchTweet route.

You should use the following path instead to reach the desired route:

127.0.0.1:3000/api/tweets/61b9af93e88ee4de51c28b95

Reference:

  • https://expressjs.com/en/guide/routing.html
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!