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

171
Views
Showing res.json is not a function
    const Express=require('express');
    const fs=require('fs');
    const app =new Express();
    // app.get("/",(req,res)=>{
    //     res.send("Hello I am at Home");
    // })
    // app.post("/",(req,res)=>{
    //     res.send("hello i am at end point");
    // })
    const tours=JSON.parse(
        fs.readFileSync(`${__dirname}/data.json`,'utf-8')
    )
    app.get('/api',(res,req)=>{
        res.json({
            status:"success",
            data:{
                tours:tours
            }
    
        })
        console.log("server running")
    })
    app.listen(8000);

Showing res.json is not a function.

Why it is showing this error? I saw a tutorial in which the code run successfully, but I am getting error?

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

0

try this code for the route

app.get('/api', (req, res) => {
    res.json({
        status:"success",
        data:{
            tours:tours
        }

    })
    console.log("server running")
})

It should be (req, res) not (res, req)

about 4 years ago · Juan Pablo Isaza Report

0

your callback parameter is reversed. it should be :

app.get('/api', (req, res) => {
... 
})
about 4 years ago · Juan Pablo Isaza Report

0

Always you have to pass req first in your callback because after req only we will get response.Like below

app.get('/api', (req, res) => {
-------
})
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!