Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Undefined reading in promise chain

I have a simple employee profile generator app. Everything works just as expected up until the promise for generatePage(employeeData). The console correctly logs employeeData but it is not getting passed to generatePage. Does anyone have insight into why? I have also included a picture of the beginning code for generate-page.js and the "undefined" console error message.

const {writeFile, copyFile} = require('./utils/generate-site.js');
const generatePage = require('./src/page-template.js');
const mockData = [
    {
       // lots of mock data objects here 
    },
]
let employeeData = mockData;

function init() {
    return inquirer.prompt(questions.startQuestions);
}
function getEmployeeData(answers) {
    if (answers.role === 'Engineer') {
        let engineer = new Engineer (
            answers.name,
            answers.id,
            answers.email,
            answers.role
        )
        return getEngineerData(engineer);
    } else if (answers.role === 'Intern') {
        let intern = new Intern (
            answers.name,
            answers.id,
            answers.email,
            answers.role
        )
        return getInternData(intern)
    } else if (answers.role === 'Manager') {
        let manager = new Manager (
            answers.name,
            answers.id,
            answers.email,
            answers.role
        )
        return getManagerData(manager)
    } 
}

function getEngineerData(engineer) {
        return new Promise((resolve) => {
            resolve (
            inquirer.prompt(questions.engineerQuestions)
            .then ((response) => {
                    engineer = {...engineer, ...response};
                    // console.log(engineer)
                    employeeData.push(engineer)
                }
            )
        )
    })
}
function getInternData(intern) {
        return new Promise((resolve) => {
        // same as getEngineerData function
    })
}
function getManagerData(manager) {
       return new Promise((resolve) => {
        // same as getEngineerData function
    })
}
function confirm() {
    return inquirer.prompt(questions.confirmQuestion)
}

function buildTeam() {
    init()
    .then(answers => getEmployeeData(answers))
    .then(confirm)
    .then(response => response.confirmAdd ? buildTeam() : console.log(employeeData))
    .then(employeeData => generatePage(employeeData))
    .then(pageHTML => {
        return writeFile(pageHTML)
    })
    .then (writeFileResponse => {
        console.log(writeFileResponse);
        return copyFile()
    })
    .then(copyFileResponse => {
        console.log(copyFileResponse);
    })
    .catch (err => {
        console.log(err);
    });
}
buildTeam();

undefined console reading at page-template.js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

console.log returns "undefined" so the solution was to return the employeeData array in the promise chain to pass on.

 .then(response => {
        if (response.confirmAdd) {
            buildTeam()
            return employeeData
        } else {
            return employeeData
        }
    }) 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda