How to set ci/cd for nodejs app with aws codeDeploy and aws codePipeline
ssh -i <key.pem> ec2-user@<ip-address> -v
sudo yum update
sudo yum upgrade
sudo yum install -y git htop wget
To install or update nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm
, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile
, ~/.zshrc
, ~/.profile
, or ~/.bashrc
).
export NVM_DIR="$HOME/.nvm"
[ -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 --version
nvm install --lts # Latest stable node js server version
node --version
npm -v
cd /home/ec2-user
git clone https://github.com/saasscaleup/nodejs-aws-codedeploy-pipeline.git
cd nodejs-aws-codedeploy-pipeline
npm install
node app.js
npm install -g pm2 # may require sudo
sudo ln -s "$(which node)" /sbin/node
sudo ln -s "$(which npm)" /sbin/npm
sudo ln -s "$(which pm2)" /sbin/pm2
sudo pm2 start app.js --name=nodejs-express-app
sudo pm2 save # saves the running processes
# if not saved, pm2 will forget
# the running apps on next boot
sudo pm2 startup # starts pm2 on computer boot
sudo yum install -y ruby
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start
Watch the rest of the youtube video...