First, need to install nvm to manage node version.
Warning
For Mac M1 Chipset: If you want to install Node.Js version ≤ 14, this’s not support the new chipset. To install, you must be install “Rosetta”
# Install LTS Versionnvm install --lts
# Install a specific versionnvm install 18
# Install lastest versionnvm install node
# switch between versionnvm use 18.17.0
# Check versionnpm -v
# Clear cachenpm cache clean -f
i
:install
D
:—save-dev
g
:—global
ls
:list
package.json is the most basic part to understand and work with Node.js , npm and also javascript . It’s saved all library and framework that you use on your project define by 2 properties dependencies and devDependencies.
Note that: with devDependencies only use for development. If the “NODE_ENV” is “production”, all package defined on devDependencies will not be installed
npm i # Install all package define on package.jsonnpm i <package-name> # install & save to dependenciesnpm i -D <package-name> # install package with dev dependenciesnpm i -g <package-name> # install package in global scope
# from github repositorynpm i git+https://github.com/abc/xyz.gitnpm i git+https://<github repo>#<new_commit_hash>
npm update <package-name> # use -g to update global
npm uninstall <package-name>
"scripts": { "serve": "eleventy --serve" "build:css": "tailwindcss -i src/assets/css/tailwind.css -o src/assets/css/main.css --postcss", "build:js": "rollup -c rollup.config.js --bundleConfigAsCjs"},
npm run server # run serve
Recently, I’m switching to Bun. Bun is a new Javascript runtime that speeds the installation & build. Bun is designed as a drop-in replacement for Node.js. It natively implements hundreds of Node.js
# install buncurl -fsSL https://bun.sh/install | bash
# check bun versionbun --version
# run a specific filebun run index.js
# run a scriptbun run start # run the `start` script
permission denied,….
# Change the permision to "current user"sudo chown -R $USER ~/.ngrok