Openssl and nodejs

This an awesome post for openssl public key private key
Here is the post for openssl certificate

At first generate ssl using openssl

1. Create a private key

$openssl genrsa 1024 > server.key

2. Create a Certificate Signing Request

$openssl req -new -key server.key -out server.csr

3. Create a ssl certificate

$openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Now use this code to run in node.js

var https = require('https');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt')

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

save file as server.js.

Now run

$node server.js

open browser, hit:

Openssl and nodejs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s