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

111
Visualizações
Problem accessing an array from within a function

I am creating a app that will scrape Indeed and then will send me an email of the array. I have scrapped the postings successfully and can send emails; but when I try to send the email all that I get is [object, Object] in my email.

const PORT =8000;
const axios = require('axios');
const cheerio = require('cheerio');
const express = require('express');
const nodemailer = require('nodemailer');

const app = express()
const url = 'https://www.indeed.com/jobs?q=Junior+engineer&l=Remote&fromage=1';

//Axios will return a promise and once the promise is returned we will get the response(data)//

axios(url)
    .then(response => {
        const html = response.data
        const $ = cheerio.load(html)
        const indeedJobPostings =[]

        //After cheerio has loaded our html, we begin by searching through a .resultContent class for our needed title and company //
        $('.resultContent',html).each(function(){
             title = $(this).find('.jobTitle').text()
             company = $(this).find('.companyName').text()
            indeedJobPostings.push({
                title, company
            })
            
        })
        ////////////
        let transporter = nodemailer.createTransport({
            host: 'smtp.gmail.com',
            port: 587,
            secure: false,
            requireTLS: true,
            auth: {
                user: 'username',
                pass: 'password'
            }
        });

        let mailOptions = {
            from: 'email',
            to: 'email',
            subject: 'Test',
            html: `<h2>Here are your daily job postings from Indeed:</h2> <ul>${indeedJobPostings}</ul>`
        };

        console.log('post log',indeedJobPostings, mailOptions)

        transporter.sendMail(mailOptions, (error, info) => {
            if (error) {
                return console.log(error.message);
            }
            console.log('success');
        });

        ///////////
    }).catch(err => console.log(err))


app.listen(PORT, () => console.log(`Server running on PORT ${PORT}`))


When I console.log(indeedJobPosting, mailOptions) indeedJobPostings prints as suspected but mailOptions sends this:

{
  from: 'email',
  to: 'email',
  subject: 'Test',
  html: '<h2>Here are your daily job postings from Indeed:</h2> <ul>[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]</ul>'
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

indeedJobPostings.push({
    title, company
})

populates the indeedJobPostings array with objects which have title and company properties. Converting this to a string in the template expression

${indeedJobPostings}

create a comma separated list of "[object Object]" strings which result from Object.prototype.toString converting the objects to strings, which are then listed by Array.prototype.toString using comma separators in its own toString operation.

You could either explicitly convert indeedJobPostings object entries to text when creating the email body, or perhaps push text in the first place:

indeedJobPostings.push(`Title: ${title}\nCompany: ${company}\n\n`);

(for example).

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