0

I am New to node.js and express.js. I Created one application with http sever. It's working fine but it is not secure. I want to create https server in that application

var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();

I got a solution: create https server like above syntaxes. How to get privateKey.pem and certificate.pem files? Please help me!

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
suresh
  • 49
  • 2
  • 10
  • If you need to create a self signed certificate you can check: https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Alexandru Olaru May 24 '18 at 05:49
  • Duplicate https://stackoverflow.com/questions/11744975/enabling-https-on-express-js – DrEarnest May 24 '18 at 06:28
  • Possible duplicate of [Enabling HTTPS on express.js](https://stackoverflow.com/questions/11744975/enabling-https-on-express-js) – Shubham Shukla May 24 '18 at 06:44
  • Please buy a certificate:) – ŞükSefHam May 24 '18 at 07:11

1 Answers1

0

You will need to generate your key and certificate. For these to work for real users, you will need to get these from a source like LetsEncrypt. However, for development purposes you can create "self signed" certificates and keys for this. With this you will get an "insecure" alert from your browser but since they're yours anyway you can click "proceed anyway".

There are many ways for generating these and many guides around for doing so. You can use this one to get a key and pem file for development purposes, and then follow the LetsEncrypt advice for production certificates.

With those, you will get your key and cert pem files generated and you will be able to read those in with the code you have above.

Elliot Blackburn
  • 3,759
  • 1
  • 23
  • 42