0

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?

coiny123
  • 1
  • 1

0 Answers0