Technical Documents

How to Install Certificates on Node.js in Linux

1. Create an https_server.js file using the following values. you can create file with any name using .js extension.

# vim https_server.js

<pre>var https = require('https');<br>var fs = require('fs');</pre>

var https_options = {
 ca: fs.readFileSync("/path/to/mydomain.ca-bundle"),
 key: fs.readFileSync("/path/to/server.key"),
 cert: fs.readFileSync("/path/to/mydomain.crt")
};
https.createServer(options, function (req, res) {
 res.writeHead(200);
 res.end("Welcome to Node.js HTTPS Servern");
}).listen(8443)

2. Now use the following command to start node.js application created in above step.

# node https_server.js