Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:04:52+00:00 2026-06-03T02:04:52+00:00

I am using nodejs and expressjs. I wonder if there is something like request.headers.protocol

  • 0

I am using nodejs and expressjs. I wonder if there is something like request.headers.protocol in the clientRequest object. I would like to build the baseUrl for the web links. So if the request was done via https I would like to keep https in all links.

    var baseUrl = request.headers.protocol + request.headers.host;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:04:54+00:00Added an answer on June 3, 2026 at 2:04 am

    Edit: For Express, it’s safer and recommended to use req.secure (as @Andy recommends below). While it uses a similar implementation, it will be safe for future use and it also optionally supports the X-Forwarded-Proto header.

    That being said, for your use case it would be quicker to use Express’ req.protocol property, which is either http or https. Note, however, that for outgoing links, you can just refer to //example.com/path, and the browser will use the current protocol. (See also Can I change all my http:// links to just //?)

    For node Request object without Express:

    It’s in req.connection.secure (boolean).

    Edit:
    The API has changed, for Node 0.6.15+:

    An HTTPS connection has req.connection.encrypted (an object with information about the SSL connection). An HTTP connection doesn’t have req.connection.encrypted.

    Also (from the docs):

    With HTTPS support, use request.connection.verifyPeer() and request.connection.getPeerCertificate() to obtain the client’s authentication details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently been playing with nodejs and would like to build my first project
I'm using nodejs w/ expressjs on a Mac and the static files (css/js/img) for
I'm using Expressjs w/ node.js and I have a route like this: users.init(app.db, function()
Am trying to implement scraping using nodejs. Am sending request to a particular url
I want to build a chat system in nodeJs + MYSQL using php. It
I am currently working on a project with 3 friends using nodeJs, expressJs, MongoDB,
In Node.js (using Express.js), when I call http.request like such: var options = {
I'm using ExpressJs with Node.js and have put all my routes into a 'routes'
I'm using RailwayJS , a Node.JS MVC framework based on ExpressJS, fully ExpressJS-compatible. I'm
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.