Express Web Server

Overview


Simple SSL Example


Place a folder called 'cert' in the directory where your web-server.js script is located. Within the cert directory, place your cert.pem, key.pem files. (a sample cert.pem file and key.pem)


const express = require('express')
const https = require('https')
const http = require('http')
const fs = require('fs')
const path = require('path')
const app = express()

let port = 443
let sslServer = https.createServer({
	key: fs.readFileSync(path.join(__dirname, 'cert', 'key.pem')),
	cert: fs.readFileSync(path.join(__dirname, 'cert', 'cert.pem'))
}, app);

app.get('/index.html', (req, res) => {
  res.send(`Hello World`);
});

app.get('/data,json', (req, res) => {
  let data = [1,2,3,4,5];
  res.send(JSON.stringify(data));
});

sslServer.listen(port, () => console.log('launch server'))
					


Contents