Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda