Tech Documents
How to Install Certificates on Node.js in Linux


This article will go into detail on how to install certificates on Node.js in Linux.
September 26, 2018
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>
<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")};</pre><pre>https.createServer(options, function (req, res) { res.writeHead(200); res.end("Welcome to Node.js HTTPS Servern");}).listen(8443)</pre>
2. Now use the following command to start node.js application created in above step.
# node https_server.js