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 #
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) #
-
https://www.reddit.com/r/node/comments/xny721/what_is_the_best_way_to_encrypt_a_password_using/
-
The password-hashing function that won the Password Hashing Competition (PHC).
Argon2 is a password-hashing function that summarizes the state of the art in the design of memory-hard functions and can be used to hash passwords for credential storage, key derivation, or other application It has a simple design aimed at the highest memory filling rate and effective use of multiple computing units, while still providing defense against tradeoff attacks (by exploiting the cache and memory organization of the recent processor
Running workers with ts-node (not really recommended as it’s slow) #
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