Node.js

Node.js #

Cloudwatch/winston logs are mixed up (not breaking line by line) #

This is caused when multiple logs log to the stderr and stdout at the same time

Parcel local server serving root html instead of ts/css/js #

Remove the “public-url” cli flag
https://github.com/parcel-bundler/parcel/issues/2855

Create GUID in nodejs #

const crypto = require('crypto');
console.log(crypto.randomUUID());

Generating a MD5 hash in NodeJS #

const crypto = require('crypto')
let hash = crypto.createHash('md5').update('some_string').digest("hex")

Generate a unique secret #

console.log(require('crypto').randomBytes(64).toString('base64'))

Directly from CLI

node -e “console.log(require(‘crypto’).randomBytes(64).toString(‘base64’));”

NPM set custom registry #

npm set registry <REGISTRY_URL>
npm adduser --registry <REGISTRY_URL>

NPM - install dependencies for a package in a different folder #

Install the on the first package, then change directory to the seond one

"npm i && cd ./<2nd_path> && npm install",

NVM install latest stable version #

nvm install --lts

Node.js build tools for windows #

https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules

Npm install on windows throws ‘gyp ERR! find Python’… #

Error: npm ERR! gyp ERR! find Python Python …`\

  • Install the latest python from the windows store

Argon2 - Best way to hash passwords in Node.js (not tested) #

node -r ts-node/register index.ts
your worker entry point is a .ts file, you instantiate it as follows:
new Worker('./worker.ts')

Create time sortable ids that contain timestamp - snowflake #

View nodejs internal memory representation (C) #

$ node --allow-natives-syntax
> const arr = [];
> %DebugPrint(arr);

List all available nvm versions #

nvm list available

NPM clear cache #

npm cache clear --force

Monorepo tools #

Resources #