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

217
Vistas
Axios not fetching EJS files properly

I'm trying to get the HTML string of two EJS files I have in my project, one is 'index.ejs' and the other is 'page2.ejs'.

I'm rendering these two in my server.js file and they are all working fine.

But the problem is when I want to fetch them to get their HTML using axios, it returns weird data.

My server code to fetch 'index.ejs' to get the HTML:

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

app.listen(5500)
app.set('view engine', 'ejs');

app.get('/', (req, res) => {
    res.render('index');
});

app.get('/page2', (req, res) => {
    res.render('page2');
});

axios('http://localhost:5500')
    .then(response => console.log(response.data))
    .catch(err => console.log(err))

The response I get back:

[nodemon] starting `node server.js`
[
  'node_modules',
  'package-lock.json',
  'package.json',
  'public',
  'server.js',
  'views'
]

And when I try to fetch 'page2.ejs' to get the HTML:

axios('http://localhost:5500/page2')
    .then(response => console.log(response.data))
    .catch(err => console.log(err))

The response I get back:

[nodemon] starting `node server.js`
Error: Request failed with status code 404
    at createError (C:\Users\user\OneDrive\Desktop\Folders\Programming\Web Development\Web-Development-Projects\Test\node_modules\axios\lib\core\createError.js:16:15)  
    at settle (C:\Users\user\OneDrive\Desktop\Folders\Programming\Web Development\Web-Development-Projects\Test\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\user\OneDrive\Desktop\Folders\Programming\Web Development\Web-Development-Projects\Test\node_modules\axios\lib\adapters\http.js:312:11)

Why am I getting wrong data on the first? and an error on the second?

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