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

130
Views
How to handle promise return inside NodeJs HTTP?

Using Cpanel, i setup a NodeJs server app as follows (mostly from the default template except for the GetSignedMessage() i included.

Users will GET a signed message from this server which returns a signed message.

var http = require('http')

async function GetSignedMessage() {
  return someSigningFunction(secret); // this returns a Promise<string>
}

var server = http.createServer(function(req, res) {

  if (req.method === "GET") {
    res.writeHead(200, {'Content-Type': 'text/plain'});

    var message = 'It works!';
    var message2 = GetSignedMessage();
    response = [message, message2].join('\n');

    res.end(response);
   }
});

server.listen();

Result when accessing the URL:

It works!
[object Promise]

How can I make the [object Promise] show as a string?

i know i should do something like GetSignedMessage().then(y => console.log(y)) where y appears as the string, but how do i store y inside message2 so it can appear in the 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!