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

204
Views
when I fetch data from server side, I got an error which is...ManageInventory.js:7 Uncaught (in promise) TypeError: res.json is not a function

Here is my index.js from server

const express = require('express');
const cors = require('cors');
const items = require('./data.json');
const port = process.env.PORT || 4000;
const app = express();
app.use(cors())
app.use(express.json())
app.get('/', (req, res) => {
    res.send('Hello....Assalamualaikum')
})
app.get('/items', (req, res) => {
    res.send(items);
})
app.listen(port, () => {
    console.log('listening from', port)
})

Here is ManageInventory.js from front end

import axios from 'axios';
import React, { useState } from 'react';
const ManageInventory = () => {
const [items, setItems] = useState([])
axios({
        method: 'get',
        url: 'http://localhost:4000/items'
    })
        .then(res => res.json())
        .then(data => console.log(data))
    return (
        <>
            <h1>This is manage Inventory page</h1>
        </>
    );
};

export default ManageInventory;

why show the res.json() is not a function?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

write res.data not res.json() Axios takes care of parsing the response automatically for us, so we don't have to call any additional methods.

about 4 years ago · Juan Pablo Isaza Report

0

Whwn i'am call axios like below then my problem is solved. Thank you all for your kind helpful information.

axios.get('http://localhost:4000/items')
            .then((response) => {
                console.log(response.data)
            })
about 4 years ago · Juan Pablo Isaza Report
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!