Skip to content

Instantly share code, notes, and snippets.

@venescu
Forked from thatisuday/server.js
Created May 16, 2021 17:03
Show Gist options
  • Save venescu/dcc00931a0373df38996065c8261366a to your computer and use it in GitHub Desktop.
Save venescu/dcc00931a0373df38996065c8261366a to your computer and use it in GitHub Desktop.
A simple HTTPS express server.
const fs = require( 'fs' );
const https = require( 'https' );
const express = require( 'express' );
// import private key and public certificate
const privateKey = fs.readFileSync( './thatisuday.key', 'utf8' );
const certificate = fs.readFileSync( './thatisuday.crt', 'utf8' );
// create an express app
const app = express();
app.get( '/', ( _req, res ) => {
res.send( "Hello Secure World!" );
} );
// launch HTTPS server on port 443
const credentials = { key: privateKey, cert: certificate };
const httpsServer = https.createServer( credentials, app );
httpsServer.listen( 443 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment