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

252
Vistas
Javascript post request leads to following error: ERR_ABORTED 405 (Method Not Allowed)

I'm trying to learn about HTTP Post requests, here's my code:

Client Side:

const options = {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                };
fetch('/api', options).then(response =>{
     console.log(response);
});

Server-Side:

const express = require('express');
const app = express();

app.listen(3000, () => console.log('listening at 3000'));
app.use(express.json({limit: '1mb' }));
app.use(express.static('public'));

app.post('/api', (request, response) => {
    console.log('I got a request!');
    console.log(request.body);
    const data = request.body;
    response.json({
        status: "success",
        latitude: data.lat,
        longitude: data.lng
    });
});

It leads to the following error on my localhost console:

ERR_ABORTED 405 (Method Not Allowed)

And it is complaining about the "fetch" line on the client side code. So there is an issue with the post. Does anyone know what the problem is?

about 4 years ago · Juan Pablo Isaza
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