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

150
Vistas
Axios Post request to Express backend gives 404

I have a simple blog site using EJS, Express, and Axios. No frontend framework - plain JS and EJS. I'm still relatively new to Express and Axios. Trying to do a simple POST request with Axios to the router file router.post("/admin/posts/create-post", adminCreatePost) and get a POST http://localhost:3000/admin/posts/create-post 404 (Not Found) error in the browser console.

The adminCreatePost function is from a separate controller file. I commented out all code and put a simple console.log("hello from the controller") in the controller and it does log the message, but still get the 404 error in the browser console. So the adminCreatePost required in doesn't seem to be the issue.

I've triple checked the url I pass in to Axios POST call. I tried a simple GET request with Axios to make sure Axios itself wasn't the problem - the GET request worked.

I'm sure it's probably something simple/silly I'm not thinking about or overlooking. Any thoughts?

If you need more info, happy to answer.

savePost.js on the frontend

    document.getElementById('save-post-button').addEventListener('click', (event) => {
        event.preventDefault();

        let postContent = [];
        let textAreas = document.getElementsByTagName('textarea');
        const arrayOfTextAreas = Array.prototype.slice.call(textAreas);
        arrayOfTextAreas.forEach(element => {
            const block = new Object();
            block.type = element.dataset.blockType;
            block.contents = element.value;
            console.log(block);
            postContent.push(block);
        })

        let newPost = {
            postReadyToView: Boolean(document.getElementById('new--ready-for-viewers').value),
            postPath: document.getElementById('new--post-path').value,
            postTitle: document.getElementById('new--post-title').value,
            postDate: document.getElementById('new--email-subscribers-date').value,
            postUpdateDate: null,
            postContent: postContent
        };

        axios.post("/admin/posts/create-post", newPost)
            .then(res => console.log(res))
            .catch(error => console.log(error))
    })

router.js on backend

const {postREQ_adminCreatePost } = require("./controllers/controllerAdmin");

router.post("/admin/posts/create-post", postREQ_adminCreatePost)

module.exports = router;

controllerAdmin.js on backend

exports.postREQ_adminCreatePost = (req, res, next) => {
  console.log('hello from controller');
  next();
}
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