node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



Build Status Code Climate Test Coverage Dependency Status devDependency Status

Simply generates all the necessary certificates for client and server TLS handshaking. The end result can be used when you need a mock server that enforces client certificate authentication.


npm install certy

Generate Certificates

Require the module and use the return certs object as needed.

var certy =  require('certy');

certy.create(function (err, certs) {

  // create a server and make requests

The create method returns a certs object that has the following...

  • serverKey: The server private key.
  • serverCert: The certificate for use by the server application.
  • clientCert: The certificate for use by the application caller.
  • clientKey: The client private key.
  • ca: The certificate authority for the client and server certs.


certy.create(function (err, certs) {

  // enable self signed certificates, not ideal for production
  // this module is design to be used in testing environments

  // server
  var options = {
    key: certs.serverKey,
    cert: certs.serverCert,
    requestCert: true,
    rejectUnauthorized: true

  var server = https.createServer(options, function (req, res) {
    res.end("hello world\n");

  // client
  let reqOptions = {
    url: 'https://localhost:4433',
    agentOptions: {
      cert: certs.clientCert,
      key: certs.clientKey

  request.get(reqOptions, function(error, response, body) {
    // if you get 'socket hung up' for the error something went wrong
    // 'hello world' should be logged to console