Run an express server on localhost with HTTP2 and SSL for free.
Serve static files or import as module in your project.
Add the rootCA.pem certificate to your list of trusted certificates. This step depends on the operating system you're running:
-
Mac OS: open Keychain Access, choose System from the left navigation bar, choose "Import items..." from the File app menu and select the file. Then double-click on the certificate and select always-trust in the Trust panel.
-
Linux: Depending on your Linux distribution, you can use
trust,update-ca-certificatesor another command to mark the generated root certificate as trusted.
From terminal navigate into the folder and run sudo npm install -g to install this tool globally.
Then serve static file with sudo serve <static-path>.
If a static path is not provided the current directory content will be served.
You must use the absolute path.
You can change the port setting the PORT environmental variable: sudo PORT=<port-number> serve <static-path>.
Install the dependency with npm install -s https-localhost.
Put in your index.js file:
const app = require("https-localhost")
// app is an express app, do what you usually do with express
app.listen(port)
If the port number is not provided, it will listen on 443.
To redirect the http traffic to https use app.redirect().
You can also serve static files with app.serve(path)
