Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!