npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

server-ssl

v42.0.1

Published

Configurable SSL Server that runs on Node.js which can be used for development or production and can create and renew Lets Encrypt Certificates automatically using ACME

Downloads

1,157

Readme

server-ssl.js

Configurable SSL Server that runs on Node.js which can be used for development or production and can create and renew Lets Encrypt Certificates automatically using ACME

Designed to get out of your way so you can still change anything about https.createServer.


Getting Started

The easiest usage would be to serve a website:

  1. Clone or Download the main branch and extract it somewhere
  2. Put your website in the website folder
  3. Open the server-ssl folder in Command Prompt or Git Bash
  4. Run npm install
  5. Run node server-ssl.js
  6. View your website at https://localhost

The default page/config is a simple API that serves and displays the time

Advanced/Production Usage

node server-ssl.js takes your arguments and starts the server

# Start for production (Lets Encrypt!) with SAN Extension
node server-ssl.js --letsEncrypt --domains=['www.ssl.boats','ssl.boats']

Optional Arguments

server-ssl.js has some optional arguments you can use in production if the defaults aren't enough.

| Arguments/Flags | Description | Default Value | |-------------------------|----------------------------------|-----------------------| | --port= | The port number for HTTPS | 443 | | --portHttp= | The port number for HTTP that will be redirected | 80 | | --cert= | The path to the SSL certificate file. | "certificate.pem" | | --pk= | The path to the private key file for the SSL certificate. | "private-key.pem" | | --site= | The directory for the website files | "wwwroot" | | --error= | The directory for error messages (404,500) | "error" | | --entry= | The page to use for the entry point | "index.html" |

All Arguments are case sensitive.

Use Lets Encrypt!

You can use Lets Encrypt to generate certificates.

Certificates are valid for 90 days but are renewed automatically sooner.

The certificates will be changed automatically when they are updated, you don't need to do anything.

| Automated Lets Encrypt! | Description | |-------------------------|----------------------------------| | --letsEncrypt | Lets Encrypt! should be used to generate 90 day certificates automatically | | --domains= | Domains to generate certificates for, this can not include wild cards, this should be an array. eg. --domains=['www.ssl.boats','ssl.boats'] | | --generateAnyway | Certificates should always be generated when the server starts, this could get you rate limited, maybe use --staging | | --staging | The Lets Encrypt! staging server should be used instead of production |

node server-ssl.js --letsEncrypt --domains=['www.ssl.boats','ssl.boats']

Always Redirect HTTP to HTTPS

HTTP requests from end users are always redirected to HTTPS

ACME Challenges transparently happen over HTTP to create/issue a new certificate


Anything Node.js can do..

At the end of the day, this is just a Node.js server that sets up SSL automatically

const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, res) => {
    // do whatever you like
})...

You can remove everything inside HTTPS_SERVER and do whatever you like.

There are also helpers you can use in STATE


Default Layout

This layout keeps the project organized and maintainable, separating error handling, website content, and server configuration.

/root
│
├── /error
│   ├── 404.html
│   └── 500.html
│
├── /ssl
│   ├── /production
│   │   │
│   │   ├── ...
│   │   ├── private-key.pem
│   │   └── certificate.pem
│   │
│   ├── /staging
│   │   │
│   │   ├── ...
│   │   ├── private-key.pem
│   │   └── certificate.pem
│   │
│   └── state.js
│
├── /wwwroot
│   └── index.html <---- Your website goes here
│
└── server-ssl.js

404/500 Pages

The server is configured to serve custom 404 and 500 error pages, instead of plain-text.

Currently everything is treated like a Server Error except for Not Found

These pages will automatically select light/dark mode


Bring Your Own SSL Certificate

Convert your certificate and private key to PEM format and place them in the ssl folder

├── /ssl
│   ├── /production <> staging
│   │   │
│   │   ├── ...
│   │   ├── private-key.pem <--- Your private key goes here
│   │   └── certificate.pem <--- Your certificate goes here