How to Install SSL Certificate on Node.js?

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)
Loading...

Steps Involved in the SSL Certificate Installation Process for Node.js

Node.js is a free cross-platform server environment, useful to servers and operating systems like Linux, Windows, Mac, Unix, etc. It is used to execute JavaScript codes outside or without a browser.

To install an SSL certificate in Node.js, you will need the SSL certificate files. The certificate authority will provide the certificate files and the private key. You will have to upload these files to the server where the Node.js application is located.

A private key will be generated when your Certificate Signing Request (CSR) is generated. Make sure you store this private key securely on the server so that no one else can access it.

Here’s AboutSSL.org’s guide on how to install an SSL certificate on Node.js.

nodejs-image

Step by Step Instructions to Install an SSL Certificate on Node.js

Step 1: Download the SSL Certificate Files

If you have completed the entire order process and have purchased your SSL certificate, you will receive an email from the certificate authority (CA) with your SSL certificate files. This includes the Intermediate and Root certificates and the CA bundle files, as well. Remember, you will receive this email only after the CA verifies your documents after you complete the purchase.

You will need the following to proceed to the next step.

  • Primary certificate for your domain
  • Root certificate
  • The CA bundle file with the intermediate and root certificates
  • Your private key
The installation process involves the following steps. You will have to create an https_server.js file and upload files to the server directory. Followed by that, you can activate your SSL certificate on Node.js.

Step 2: Create https_server.js File and Upload SSL Files

Here, you can rename “Server.js” as you wish and the following values will help create your https server, the https_server.js file.
#vim https_server.js
var https = require('https');
var fs = require('fs');
var https_options = {
key: fs.readFileSync("/path/to/private.key"),
cert: fs.readFileSync("/path/to/your_domain_name.crt"),
ca: [
fs.readFileSync('path/to/CA_root.crt'),
fs.readFileSync('path/to/ca_bundle_certificate.crt')
]
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("Welcome to Node.js HTTPS Servern");
}).listen(8443)
In the above, replace the text in bold with the following.
  • path/to/private.key – This is your private key file’s path.
  • path/to/your_domain_name.crt – Enter your SSL certificate file’s path.
  • path/to/CA_root.crt – Provide the CA root certificate file’s full path.
  • path/to/ca_bundle_certificate – This is the full path of your uploaded CA bundle file.

95%
OFF

comodo-square-logo

Comodo Positive SSL

$6.55

Vendor Price: $41.73

Coupon Code: ASCSCPSSL4

Get It Now

78%
OFF

rapidssl-coupon-square-logo

RapidSSL Certificate

$13.45

Vendor Price: $69

Coupon Code: ASRSRSSL2

Get It Now

95%
OFF

comodo-square-logo

Comodo PositiveSSL Multi-Domain

$17.54 – 2 SAN Included

Vendor Price: $41.73

Coupon Code: ASCSCPMD4

Get It Now

Step 3: Activate SSL Certificate on Node.js

Running the following command will help launch the Node.js application.
# node https_server.js

Once you run this command, your SSL Certificate will be active on Node.js.

You can check whether your certificate has been installed using an online SSL checker tool.

Related Articles:

Download Site Seal
comodo-trust-seal
SSL Checker