Can nodejs generate SSL certificates?


I'm writing a proxy support HTTPS-HTTPS proxy. Before i use Python as the main programming language, but i'm interested in node.js now, so i prepare to migrate.

The largest problem i'm facing is that i don't know how to generate CA and other server certificates in node.js. In Python, there is pyOpenSSL which is awesome. I don't find something similar in node.js until now.

Maybe i should use openssl-fork method? But how to handle the interactive operation in openssl.

Thank you.

3/1/2012 4:11:11 PM

Accepted Answer

In case somebody does want to programatically create CSRs from node.js, I have created a nodejs module which uses openssl to create a private key and a CSR.

Edit: Use pem instead. It is much more complete and probably more reliable.

Edit2: Actually, pem is also just a simple wrapper over openssh. For a pure js implementation, look into forge

6/1/2015 6:13:08 AM

Use shell for certificate:

openssl genrsa -out server-key.pem 1024
openssl req -new -key server-key.pem -out server-csr.pem
openssl x509 -req -in server-csr.pem -signkey server-key.pem -out server-cert.pem

Then use them in node.js

var https = require('https');
    key: fs.readFileSync('server-key.pem'),
    cert: fs.readFileSync('server-cert.pem')
function (req,res) {


You can also give a try to this project in NPM :

I found it searching the NPM repo :

I did not tried or checked it myself, but it looks like a way to generate the certificate using node, which is the original question.

var openssl = require('openssl-wrapper');
var password = 'github';

return openssl.exec('genrsa', {des3: true, passout: 'pass:' + password, '2048': false}, function(err, buffer) {

I'd be interested by a feedback. ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow