• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

88
Views
Request failed to display user data from Express js

Im trying to get data from my API backend (express.js) to my Vue client but every time i got "status failed or canceled", i haven't any error on my console except this :

image here

That my backend code route.js :

const express = require('express')
const router = express.Router()
const { ensureAuth, ensureGuest } = require('../middleware/auth')
const bodyParser = require("body-parser");
const User = require('../models/User')
const cors = require("cors");
const app = express();

app.use(bodyParser.urlencoded({ extended: true }))

// use cors options
app.use(cors(corsOptions))

app.use(express.json())

router.get('/', ensureGuest, (req, res) => {
  res.render('visual')
})

router.get('/userInfo', ensureAuth, async (req, res) => res.json({displayName : 'John Doe'}))

My Vue script dashboard.vue :

<template>    
  <img src="@/assets/images/avatars/0.jpg" alt="User Avatar"> <span>{{info.displayName}}</span>
</template> 

<script>
   import axios from 'axios';
   export default {
    data() {
    return {
      info: null,
      }; 
   },
  created() {
    axios.get('http://localhost:3000/userInfo')
.then(res => {
  this.info = res.data;
  })
 },
};
</script>
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error