Nodejs

Installation

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

nvm i --lts

nvm i --lts --reinstall-packages-from=node

nameexplain
npm-check-updatescheck updates
pkgpack as single executable
pm2process managment
zxjs like bash
prettiercode style
yargscli framework
leranmonorepo

NPM

# list all packages
npm ls -g --depth=0
# init projects
npm i -y

Run node service

  1. Use pm2
pm2 start --name app npm start
  1. Use systemd
[Unit]
After=network.target

[Service]
Environment=NODE_PORT=3000
Type=simple
User=ubuntu
ExecStart=/usr/bin/node /home/ubuntu/app.js
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo cp app.service /etc/systemd/system/
sudo systemd daemon-reload
sudo systemd start app
  1. Use docker
FROM sigoden/node:native as builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --prod

FROM sigoden/node:slim
WORKDIR /app
COPY --from=builder /app .
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]

Native addon

  1. INstall deps like gcc, make, python
# ubuntu
apt install build-essential

# alpine
apk add make gcc g++ python3 git
  1. Test native addon
npm i --build-from-source bcrypt

ES features

https://node.green