Node JS

NPM packages for node js web development 1. validators 2. Chalk 3. yargs 4. request 5. postman-request Debugging 1. Console.log 2. debugger ( node inspect app.js) 3. chrome://inspect/#devices Real Time Weather API darksky and weather stack api.weatherstack.com/current?access_key=&query=37.8367,-122.4233 Location Access mapbox.com Handlbars 1. nodemon app.js -e js,hbs Server Setup 1. yum -y update 2. yum -y groupinstall "Development Tools" 3. yum -y install vim net-tools 4. yum -y install node.js 5. npm install -g pm2 http-server 6. install yarn package maanger -- yum -y install yarn create a new user (non -root) in server instead run this in root user 1. adduser user_name 2. usermod -aG wheel user_name 3. sudo su -user_name mkdir .ssh chmod 700 .ssh touch .ssh/authorized_keys chmod 600 .ssh/authorized_keys copy ssh key by cat ~/.ssh/id_rsa.pub vim .ssh/authorized_keys Now deploying node js app 1.copy project files in to live server 2. the run node package modules. 3. Now its time to run the server after close our server console. pm2 start --name project_name_dir index.js 4. pm2 ls to anable auto start server in pm2 we need root access to configure 5. pm2 startup systemd -u user_name --hp /home/[project_path] 3. pm2 save ( save that state of application running) Automate Node.js Deployment create deploy.sh script #!/bin/bash tar czf project_name.tar.gz index.js package.json yarn.lock public scp project_name.tar.gz remote_ip:~ rm project_name.tar.gz ssh remote_ip << 'ENDSSH' pm2 stop project_name rm -rf project_path mkdir project_path tar xf project_name.tar.gz -C project_name cd project_name yarn install pm2 start project_name ENDSSH Run on port 80