Setting Up a Node.js Server on EC2
A barebones guide to setting up a Node.js server on AWS EC2.
Initial AWS Setup
Follow the AWS EC2 Getting Started guide. This article assumes an Amazon Linux AMI configuration (2017.03.0 HVM). Follow the AWS documentation through Step 3 (Configure your instance).
SSH EC2 Instance
Move your newly created PEM file to your root SSH folder.
mv ./your-app-key.pem /.ssh
Access your EC2 instance via SSH by providing your local PEM file and the DNS or IP address of your instance. The command below uses the AWS domain name instead of IP. If you're using a Ubuntu server, connect with user name
ssh -i ~/.ssh/your-app-key.pem [email protected]
sudo apt-get install git
sudo apt-get install nodejs
To access Node and check the version installed, run the following command
sudo apt-get install npm
Install your Node.js project via Git. For this example, we'll clone the repository for this site.
git clone https://github.com/mkamla/node-portfolio.git
Next, change your working directory and install the projects dependencies
Finally, if there are configuration files, such as
.env, set those values for production as specified by your project.
If you cloned the repository for this site, please continue reading, otherwise skip ahead to the Starting your server section.
This project utilizes Wakatime and several other AWS services. You will be required to provide your own API access keys. Once the access keys have been created, copy the .example.env in the root directory and name this newly created file
.env. Finally, edit the file in nano and replace the psuedo keys with your API access keys.
cp ./.example.env ./.env
Starting your server