Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda