A simple boilerplate express server using https
This will run the server with http and https.
npm install
npm start
- Running HTTP xor HTTPS If you just want to run the server on http
npm run http
If you just want to run the server on https
npm run https
- Adding a port option
npm run http --port=3000
or
npm run https --port=3000
But you cannot run
npm start --port=3000
since you will not be able to start to different express instances on port 3000. It won't fail, but it won't take into account the argument. Two environment variables are available to customize. They are
HTTP_PORT
HTTPS_PORT
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
Using Let's Encrypt to generate a certificate
- Certbot
- Domain Name
sudo certbot certonly --standalone -d {domain}.com -d www.{domain}.com # Generates a standalone certificate for your domain
sudo chmod 755 /etc/letsencrypt/live /etc/letsencrypt/archive # Allows nodejs to read the certificate and private key