Basic NodeJs setup on Ubuntu 16.04
1. Install NodeJs
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install nodejs
2. Create a symlink of nodejs to node
ln -s /usr/bin/nodejs /usr/bin/node
3. Install NPM
sudo apt-get install npm
4. Navigate to your App directory
cd /path/to/app
5. Install App's dependencies
sudo npm install
6. Install PM2
sudo npm install pm2 -g
7. Setup PM2 to start on ubuntu boot
pm2 startup ubuntu #This will print a command like below. Run the command with su privilege.
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup ubuntu -u ubuntu --hp /home/ubuntu
8. Start Application using PM2
pm2 start app.js
9. Check Application status
pm2 show app
10. Check Application logs
pm2 logs app
11. Setup Nginx as reverse proxy
server {
listen 80;
listen [::]:80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
12. Reboot Nginx
sudo service nginx restart
AI Summary
Chrome On-device AI
2024-09-19 19:44:51
Share Article