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

265
Views
How to pass a variable from a post request to a function that takes params as string or array of string in Node.js?

I would like to pass the variable below called query into the end of the prompt , I tried template literals but it doesn't work

(async () => {
  const gbtResponse = await openai.createCompletion({
    model: "text-davinci-002",
    prompt:
      "Generate a product description explanation for the following product:  \n\n",
    temperature: 0.8,
    max_tokens: 256,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });
  console.log(`${gbtResponse.data.choices[0].text}`);
  // console.log(`${gbtResponse}.choices[0].text`);
  app.get("/api", (req, res) => {
    res.send(`${gbtResponse.data.choices[0].text}`);
  });
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));

  app.post("/api", (req, res) => {
    res.send(
      `I received your POST request. This is what you sent me: ${req.body.productName}`
    );
    const query = req.body.productName;
    console.log(`${query}`);
  });
})();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think what you will need to do is this:

  const gbtResponse = async (param) => {
    return await openai.createCompletion({
    model: "text-davinci-002",
    prompt:
      `Generate a product description explanation for the 
      following product: ${param} \n\n`,
    temperature: 0.8,
    max_tokens: 256,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });
}

and then rather than referring it you need to call it.

Since you specified you don't want to use template literals you could use this approach.

    prompt:
      "Generate a product description explanation for the 
      following product: " +  param + "\n\n",
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!