From 5c041c0e3539c0f38b205c569e8f27b02f67b678 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 13 Jul 2020 07:38:19 +0000 Subject: [PATCH] update formatting, add random key gen --- node/README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/node/README.md b/node/README.md index 75fe146..6f9ae8a 100644 --- a/node/README.md +++ b/node/README.md @@ -5,7 +5,7 @@ tagline: | Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. --- -## Updating `node` +## Updating and Switch versions ```bash webi node@stable @@ -16,8 +16,8 @@ Use `@lts` for long-term support and the `@beta` tag for pre-releases, or ## Cheat Sheet -Node is great for simple, snappy HTTP(S) servers, and for stitching APIs -together with minimal fuss or muss. +> Node is great for simple, snappy HTTP(S) servers, and for stitching APIs +> together with minimal fuss or muss. Installing node via webi will: @@ -55,11 +55,26 @@ http.createServer(app).listen(8080, function () { node server.js ``` +### Generate a Secure Random Key + +This generates a hex-encoded 128-bit random key. + +```bash +node -p 'crypto.randomBytes(16).toString("hex")' +``` + +This generates a url-safe base64 256-bit random key. + +```bash +node -p 'crypto.randomBytes(32).toString("base64") + .replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")' +``` + ### An Express App ```bash mkdir my-server -pushd my-server +pushd my-server/ npm init npm install --save express ``` -- 2.25.1