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

387
Views
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 answers
Answer question

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 Report
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!