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

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