Self-signed certs with secure WebSockets in Node.js

First generate your self-signed certs:

Then create your httpsServer from an express app using node’s built-in https server:

Then setup your websocket server (ironically this will use the same port as the http server, I didn’t know this but I guess protocols can share ports? — this had me going for awhile).

Now browse to https://0.0.0.0:8443 server and accept the self-signed cert in Chrome. Then websockets should now work isnide the browser.

Open a chrome devtools console and type:

Managing config variables inside a Node.js application

In the interest of avoiding debate over this post, let’s just say there is more than one way to skin a cat when it comes to configuration management in an application. Some like to keep it out of the code base, others prefer it. This method stores the config files in the repository.

There is more than one way to handle configuration variables based on an environment for a node.js app, but I’ve come up with a pretty simple solution that keeps my config variables DRY and complete control to override them at the same time using different node environments.