Nodejs Notes

How to uninstall nodejs from mac

use command

which node

to find where the node executable is

Start a quick server

npm install -g http-server

go to location with static web files then start the server using:

http-server

check peer dependency

npm info name-of-module peerDependencies

4 ways of reading lines from file

Reading Async:

const fs = require('fs').promises;
async function loadMonoCounter() {
    const data = await fs.readFile("monolitic.txt", "binary");
    return Buffer.from(data);
}

Regular Expression

print out boolean value:

let a=true
console.log(`${a}`);

Install nodejs from binary on Windows

Install different version of nodejs using Homebrew

brew install node@14
nano ~/.zshrc
alias node16='export PATH="/usr/local/bin:/usr/local/opt/node@16/bin:$PATH"; node -v'

Save the file with control + O and hit enter. Exit the editor with control + X.
Now the next time that you open up a new terminal, you can just type node16 to switch to Node.js 16.
Running bash instead of zsh is no problem. Just put the above code in your .bashrc file instead of the .zshrc file.

Async and await in loops

  • ForEach is not promise aware
  • map – use promise.all
  • for loop – await is executed in sequence as expected