Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda