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

249
Views
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
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!