- Install brew (package manager for mac os)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Install mkcert[https://github.com/FiloSottile/mkcert] a. For mac
brew install mkcert
b. For windows Follow this instructions to install the mkcert.
- Generate trusted cerificate locally
$ mkcert -install
Created a new local CA
$ mkcert [domain name]
# In our case, we will use localhost
$ mkcert localhost
Above step will create couple of files [domainname]-key.pem, [domainname].pem.
- Create an node app and create server js file.
npm init
touch server.js
- Install express js
npm install express
- Copy these files created in step 3 [domainname]-key.pem, [domainname].pem and paste it in this folder.
- Include this below code in server.js
'use strict';
const https = require('https');
const express = require('express');
const fs = require('fs');
const options = {
key: fs.readFileSync('[domainname]-key.pem'),
cert: fs.readFileSync('[domainname].pem'),
};
const app = express();
app.get('/', (req, res, next) => {
res.send("Localhost hosted in https !")
});
https.createServer(options, app).listen(3000);
- Test the application by opening the browser and hitting the URL
https://localhost:3000/