Posts

Git Hooks for Node.JS

We need to create git hooks to deploy node applications directly by pushing to a specific origin. For this, we need a folder for git repo and a folder for hosting. For continuous execution of node.js code, we will use PM2. Our environment will be as follows; Git Repo: /var/repo/git_repo Hosting Folder: /var/www/hosting Git Branch: main    Following steps to be followed; Step 1: Server-side # Install PM2 on server  $ npm install pm2 -g # Initialize Git repo $  git init --bare /var/repo/git_repo # Cloning the repo to hosting folder - this will give warning of cloning empty repo $ git clone /var/repo/git_repo /var/www/hosting # Editing post receive hook of git repo $ vim /var/repo/git_repo/hooks/post-receive #!/bin/bash echo 'post-receive: Triggered' cd /var/www/hosting git --git-dir=/var/repo/git_repo --work-tree=/var/www/hosting checkout main -f echo 'post-receive: Cloning complete'   cd /var/www/hosting \ && npm install \ && echo 'post-receive: i...

Running NodeJs API with Apache & PM2 on Ubuntu

Use the following steps; 1. Install Apache, Node, NPM using APT 2. Install PM2 using NPM 3. Configure apache to use proxy sudo a2enmod proxy sudo a2enmod proxy_http sudo service apache2 reload 4. Create configuration file for site as /etc/apache2/site-available/webname.conf <VirtualHost *:80>         # The ServerName directive sets the request scheme, hostname and port that         # the server uses to identify itself. This is used when creating         # redirection URLs. In the context of virtual hosts, the ServerName         # specifies what hostname must appear in the request's Host: header to         # match this virtual host. For the default virtual host (this file) this         # value is not decisive as it is used as a last resort host regardless.         # However, you must set it for any further virtual host explicitly.    ...