In this tutorial, we will cover the steps to deploy an Express.js application to Oracle Cloud. We will use Oracle Cloud Infrastructure (OCI) to create a virtual machine and deploy our application to it.
- An Oracle Cloud account
- A basic understanding of Node.js and Express.js
- Node.js and npm installed on your local machine
Step 1: Creating a Virtual Machine on OCI
Log in to your Oracle Cloud account and navigate to the OCI dashboard. Create a new virtual cloud network (VCN) if you haven't already done so.
- Create a new subnet within a VCN or leave the defaults for a public IP address
- Configure the instance settings, including the operating system and SSH key. Ensure you download and save the key since this is how you will access your virtual instance and deploy your application.
Step 2: Setting up the Virtual Machine
Connect to the virtual machine instance using SSH and install Node.js and npm on the virtual machine using the following commands:
sudo yum install nodejs
sudo yum install npm
You can clone your Express.js application repository directly onto the virtual machine using Git or you can copy it from your local device (on mac or linux) with the
scp -i my-key.pem myapp user@public-ip-address:~/myapp
For further instructions on creating an ssh key and connecting see documentation here.
Step 3: Configuring the Virtual Machine Firewall
- Configure the firewall on the virtual machine instance to allow inbound traffic on the port that your Express.js application will be listening on (usually port 3000).
- Save the firewall configuration.
Step 4: Running the Express.js Application on the Virtual Machine
Navigate to the directory where your application is located.
Start your application by running the following command:
Test your application by navigating to the public IP address of the virtual machine instance in your web browser followed by the port number your application is listening on (e.g. http://<public_ip_address>:3000).
You can also setup your application to listen on ports 80 or 443, and add a load balancer for SSL termination. In addition, if you were to launch this as a website, you can dockerize the application (see our MERN stack for example) and run it as a service with automatic restarts.
In this tutorial, we have covered the steps to deploy an Express.js application to Oracle Cloud. By creating a virtual machine instance on OCI, configuring the firewall, and running our application, we were able to make it accessible to the public. With the optional step of setting up a domain name, we can make our application even more user-friendly.