Created
January 6, 2024 04:30
-
-
Save vpadhariya/8c322370db5e335b59dd980a519394c0 to your computer and use it in GitHub Desktop.
Here how we can enable https server for Express Node Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
var bodyParser = require('body-parser') | |
const mongoose = require('mongoose'); | |
const routes = require('./routes/routes'); | |
// for HTTP and HTTPS listening | |
var fs = require('fs'); | |
var http = require('http'); | |
var https = require('https'); | |
var privateKey = fs.readFileSync('{PATH TO PRIVATE KEY}/privkey.pem', 'utf8'); | |
var certificate = fs.readFileSync('{PATH TO CERTIFICATE}/fullchain.pem', 'utf8'); | |
var credentials = {key: privateKey, cert: certificate}; | |
// ... | |
// Your other app settings | |
app.use(cors()) | |
app.use(bodyParser.urlencoded({extended: true})) | |
app.use(bodyParser.json()); | |
// app.use(express.json()); | |
app.use(express.static('public')); | |
app.use('/', routes); | |
// ... | |
var httpsServer = https.createServer(credentials, app); | |
httpsServer.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment