Nodejs ssl for frontend

1.Generate certificate for test.

Furthermore the core library of the OpenSSL project can be used to generate self-signed certificates. These certificates can then be used for testing purposes.

openssl genrsa -des3 -out server.enc.key 1024
openssl req -new -key server.enc.key -out server.csr
openssl rsa -in server.enc.key -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

2.Config Nodejs

PAY ATTENTION: be careful if your REST not HTTPS.

In this example we only add ssl for ui.

var fs = require('fs');
var https = require('https');
var app = require('express')();
var options = {
   key  : fs.readFileSync('server.key'),
   cert : fs.readFileSync('server.crt')

app.get('/', function (req, res) {
   res.send('Hello World!');

https.createServer(options, app).listen(3000, function () {

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

Create a website or blog at

Up ↑

%d bloggers like this: