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

170
Views
Javascript POST busca en el servidor Express.js que devuelve 405 (método no permitido)

Estoy tratando de crear una aplicación con Node y Express, y en el archivo script.js especifico una solicitud de búsqueda para la ruta API POST que definí, que se ve así:

 //Post to the database with a fetch request fetch("/api/characters", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify(character), }) .then(response => { if (response.ok) { return response.json(); } alert("Error "+response.statusText); });

La ruta que definí en server.js se ve así:

 //POST a character to the database app.post("/api/characters", (req, res) => { let character = req.body; //Get the db.json file fs.readFile(path.join(__dirname, "/db/characters.json"), "utf8", (err, data) => { if (err) { throw err; } if (data) { let charactersArray = JSON.parse(data); charactersArray.push(character); } fs.writeFileSync(path.join(__dirname, "/db/characters.json"), JSON.stringify(charactersArray, null, 4), (err) => { if (err) { throw err; } console.log("Successfully wrote character to db"); }); res.send("Successfully wrote character to db"); }); });

Probé la ruta POST en Insomnia anteriormente y parece que funciona, por lo que estoy bastante seguro de que el problema radica en la solicitud de recuperación, pero me parece que la ruta y el método proporcionados son correctos, así que no estoy seguro de por qué. el POST dice que no está permitido.

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!