Skip to content

Instantly share code, notes, and snippets.

@alabhyajindal
Last active October 26, 2023 09:57
Show Gist options
  • Save alabhyajindal/ee71ce60bb4b3f023e88f4384332b9d1 to your computer and use it in GitHub Desktop.
Save alabhyajindal/ee71ce60bb4b3f023e88f4384332b9d1 to your computer and use it in GitHub Desktop.
Deploy Express application on a virtual server
# Update dependencies
echo "Updating dependencies..."
apt-get update
apt update
# Ask for GitHub source code URL
echo "\nWhat is the URL of your GitHub public repo that you want to deploy?\n"
read url
source_code="$url.git"
# Ask for Domain name
echo "\nWhat is your domain name?"
read domain_name
# Clone the source code (assuming the domain name)
rm -rf /var/www/html/$domain_name
git clone $source_code /var/www/html/$domain_name
# Install nginx
echo "\nInstalling nginx..."
yes | apt install nginx
# Instal Node.js using NVM
echo "\nInstalling Node.js..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install --lts
nvm use --lts
# Configure nginx
echo "\nConfiguring nginx..."
new_config="server {
listen 80;
server_name _;
location / {
proxy_pass http://127.0.0.1:3000;
}
}"
current_config="/etc/nginx/sites-available/default"
echo "$new_config" > "$current_config"
# Enable and start nginx
echo "\nStarting nginx..."
ufw allow "Nginx HTTP"
ufw enable
systemctl enable nginx
systemctl start nginx
# Install NPM packages
cd /var/www/html/$domain_name
npm install
# Start the Express application
node main.js
@alabhyajindal
Copy link
Author

Usage

  1. ftp https://gist.githubusercontent.com/alabhyajindal/ee71ce60bb4b3f023e88f4384332b9d1/raw/736b76690ca3907fc34daa300e125dfa2b387bed/deploy.sh
  2. sh deploy.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment