Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda