Menu
picture of tbs certificates
picture of tbs certificates
Certificates
Our products range
Partners
Support
Focus


Installing a certificate on Node.js

To install a certificate on Node.js, you must first go to the certificate status page (link available in the delivery email). Click on the "View Certificate" button and in the window that appears, retrieve:

  • your certificate: click on the link starting with "cert-XXXXXXXX" to download your certificate.
  • the certification chain: click on "View certification chain" and then click on the TXT file starting with "chain-XXXXXXXX".

Once these files are retrieved, make them available on your server along with your private key that you generated when you ordered the certificate.
Then create a configuration file for node.js. For example with this command :

    #vim https_server.js // Note: you can choose another filename if you wish

In this file, here are the parameters to be entered :

1) Importing a certificate, its private key and the certification chain with 3 separate files.

    var https = require('https');
    var fs = require('fs');
    var https_options = {

    key: fs.readFileSync("/path/to/privatekey.key"),

    cert: fs.readFileSync("/path/to/cert-XXXXXXXXXX.cer"),

    ca: fs.readFileSync('path/to/chain-XXXXXXXXXX.txt')

    };

    https.createServer(options, function (req, res) {

        res.writeHead(200);
    
        res.end("Hello");

    }).listen(8443)

2) Importing a PFX

    var https = require('https');
    var fs = require('fs');
    var https_options = {

    pfx: fs.readFileSync("/path/to/your_file.pfx"),

    passphrase: 'PFX password'

    };

    https.createServer(options, function (req, res) {

        res.writeHead(200);
    
        res.end("Bienvenue");

    }).listen(8443)

All you have to do is start Node.js with the command :

    # node https_server.js

Useful links