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

390
Vistas
How is -u of curl request is accessed in node js request message?

I have curl request as below,

curl -u user:password http://localhost:3000/user

How do I access the user and password passed in the http request on the server?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The option -u specifies the username and password for the HTTP Basic Authentication.

It is accessible via the Request-Header Authorization (req.headers.authorization), but is encoded with base64.

The below code will read the header and decode the string, and then store the username and the password in seperate variables.

const b64auth = (req.headers.authorization || '').split(' ')[1] || ''
const strauth = Buffer.from(b64auth, 'base64').toString()
const splitIndex = strauth.indexOf(':')
const login = strauth.substring(0, splitIndex)
const password = strauth.substring(splitIndex + 1)

For more information see Basic HTTP authentication with Node and Express 4

over 4 years ago · Santiago Trujillo Denunciar
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