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

96
Views
Rest API, take request fields. handle

I stood in a stupor. And I need help.
I do rest full api on express

I want to do this if a request comes in type: reset_password -> I sent an email to reset my password.(it can be both registration and auth)

But I don't know how to pass it into a query. And that is, how to do it. I trimmed the code.


const send = async (req, res) => {
    const key = req.query.apiKey;
    const type = req.query.type;
    const to = req.query.to;
        if (err) {
            console.log(err);
        } else if (rows.length == 0) {
            res.status(401).json({"apiKey":"error"})
              } else {
                  if (email.validate(to)) {
                        sendmail(type, to)
                      } else {
                        res.status(422)
                }
            }   
}

sendmail:

const nodemailer = require("nodemailer");
const ejs = require('ejs')
const path = require('path')

const sendmail = async (type, to, url) => {
  try {
    const reset_password = path.join(__dirname, "../template/resetpassword.ejs")
    const signup_auth = path.join(__dirname, "../template/signupauth.ejs")
    const sign_in_auth = path.join(__dirname, "../template/signinauth.ejs")
    const data = await ejs.renderFile(reset_password,signup_auth,sign_in_auth, { to, url } )

    let testAccount = await nodemailer.createTestAccount();

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
      host: "smtp.ethereal.email",
      port: 587,
      secure: false, // true for 465, false for other ports
      auth: {
        user: testAccount.user, // generated ethereal user
        pass: testAccount.pass, // generated ethereal password
      },
    });
   
   const send = await transporter.sendMail({
      from: 'dev@test.io',
      to: to,
      text: "Hello world?",
      subject: "test",
      html: ??? 
  })

  console.log("Success send: %s", nodemailer.getTestMessageUrl(send));

  }catch (err) {
    console.log('Error send: ' + err.message);
  }
}
module.exports = sendmail;

Now I have a question. How do I send a request: reset_password,signup_auth,sign_in_auth
That is, how do I pass it on to the type: reset_password,signup_auth,sign_in_auth

http://localhost:3000/api?apiKey=key&type=reset_password,signup_auth,sign_in_auth

How do I take it and process it?
I need to accept type=auth signup reset to api rest I'm sorry, maybe I didn't make my point correctly.
about 4 years ago · Juan Pablo Isaza
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!