Amazon price checker

Hii, Everyone i’m actually creating a amazon price checker by watching a video on internet by " [Web Dev Simplified]" The code i written is not sending an email can anyone tell me where did i went wrong and why my code is not sending an email

require('dotenv').config()

const sgMail = require('@sendgrid/mail')

sgMail.setApiKey(process.env.SENDGRID_API_KEY)

const nightmare = require('nightmare')()

const arguments = process.argv.slice(2)

const url = arguments[0]

minPrice = arguments[1]

checkPrice()

async function checkPrice() {

   const priceString = await nightmare.goto(url)

                                      .wait("#priceblock_ourprice")

                                      .evaluate(() => document.getElementById("priceblock_ourprice").innerText)

                                      .end()

const priceNumber = parseFloat(priceString.replace('₹', ''))

    if (priceNumber < minPrice) {

      sendEmail(

        'price is low',

        `The price on ${url} has dropped to ${minPrice}`

      )

    } 

}

function sendEmail(subject, body) {

    const email = {

        to: "lolanix291@fleeebay.com",

        from: "Price-checker-project@example.com",

        subject: subject,

        text: body,

        html: body

    }

    return sgMail.send(email)

}

Hm… I don’t use sendgrid package so I can’t say for certain why it’s not working. So you said you’re watching video for this, have you checked out the package on github? There’s instructions and you can also check the issues raised, if other people had similar problems and got it solved:

https://github.com/sendgrid/sendgrid-nodejs

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Other than sendGrid package which package would you suggest me for sending Email.??

Thanks for responding, I’ll do better from next time

to troubleshoot this better together are you getting any error in the console ?
if debugging the code when you put a breakpoint does the code get to call the sendEmail() ?

The code in the repo has an await in front of the call to sendEmail

await sendEmail('whatever', 'something')

It also has a try/catch you might want to implement as well.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.