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

110
Vistas
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 Respuestas
Responde la pregunta

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 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