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

134
Views
Assign a HTTP response body as variable for my hapi.js handler

How do I assign a variable from the HTTP response body of an HTTP request? I tried doing it like this, but it's getting a 502 error.

const https = require('https')
const getDadJokes = async (request, h) => {
    const dadJokesApi = {
        hostname: 'icanhazdadjoke.com',
        method: 'GET',
        path: '/', 
        headers: {
            'Accept': 'text/plain',
        },
    }
    const dadJokes = https.request(dadJokesApi, (res) => {
        res.on('data', (body) => body);
    });
    dadJokes.end();
    const response = h.response(dadJokes);
    return response;
};
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!