A .cer can be encoded using two different formats: PEM and DER .
If your file is encoded using the PEM format, you can simply use it like any other .pem file (more information on this can be found in Node.js :
const https = require("https"); const options = { key: fs.readFileSync("key.pem", "utf8"), cert: fs.readFileSync("cert.cer", "utf8") }; https.createServer(options, (req, res) => { res.writeHead(200); res.end("Hello world"); }).listen(8000);
If your file is encoded using the DER format, you first need to convert it to a .pem file using OpenSSL (the command was taken from here ):
openssl x509 -inform der -in cert.cer -out cert.pem
and then can use the above code with cert file name cert.pem instead of cert.cer :
const https = require("https"); const options = { key: fs.readFileSync("key.pem", "utf8"), cert: fs.readFileSync("cert.pem", "utf8") }; https.createServer(options, (req, res) => { res.writeHead(200); res.end("Hello world"); }).listen(8000);
If you have a certificate authority key that matches your cert.cer file, you can include it in the options https.createServer argument as follows (the sample code assumes that the file is named ca.pem and that it is encoded using the PEM format):
const https = require("https"); const options = { ca: fs.readFileSync("ca.pem", "utf8"), key: fs.readFileSync("key.pem", "utf8"), cert: fs.readFileSync("cert.pem", "utf8") }; https.createServer(options, (req, res) => { res.writeHead(200); res.end("Hello world"); }).listen(8000);
For more information about https.createServer and its arguments, see the documentation .
Note. All of the above options assume that you also have a public key encoded in PEM format with the name key.pem and that the .cer file is named cert.cer . If you do not have a public key, please comment or add it to the question, and I will update the answer accordingly.
If you donβt know what format your file is encoded in, you can try both options, see which one suits you.