Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

getting "unexpected end of file" axios error while making a get request in this small nodejs app

Writer Andrew Mclaughlin

I have been getting this error in this small nodejs app while trying to learn using axios on the backend to make request. "unexpected end of file".

axios request file

import axios from "axios";
export const getData = async () => { let data; try { const response = await axios.get( "" ); console.log(response); data = response; } catch (error) { console.log(error.message); return; } return data;
}; 

server.js

import express from "express";
import cors from 'cors';
import axios from "axios";
import { getData } from "./utils/getData.js";
const app = express();
app.use(cors());
app.use(express.json());
app.get("/", async (req, res) => { let users; users = await getData(); res.send(users);
})
app.listen(5000, () => { console.log("server listening at port 5000");
})
2

3 Answers

You can add below header encoding to your request.

axios.get("url", { headers: { "Accept-Encoding": "gzip,deflate,compress" }
});
2

the Brotli decompression bug was fixed in v1.2.2

Bro, go to Package.json--> in dependencies --> check for axios ---> Add 'axios' : '1.1.3'.

This will solve your issue.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.