Free Tier: Install Node Express on an Oracle Linux Instance
In this tutorial, you use an Oracle Cloud Infrastructure Free Tier account to set up
an Oracle Linux compute instance. Then, you install a Node Express application and access
your new app from the internet. Finally, this tutorial covers all the steps necessary to set
up a virtual network for your host and connect the host to the internet.
Key tasks include how to:
Set up a compartment for your development work.
Install your Oracle Linux instance and connect it to your Virtual Cloud Network
(VCN).
Set up an Oracle Cloud Infrastructure virtual cloud network and related
network services required for your host to connect to the internet.
Set up ssh encryption keys to access your Oracle Linux
Server.
Configure ingress rules for your VCN.
Configure NodeJS with an Express framework on your instance.
Here is a simplified diagram of the setup for your Linux instance.
To get started installing an instance with the Create a VM instance workflow, follow these steps:
Important
The steps provided are for a Free Tier account. If you are using a paid account, the steps might differ from those shown here.
Open the navigation menu and select Compute. Under Compute, select Instances.
Click Create Instance.
The Create compute instance page is displayed.
Choose the Name and Compartment.
Initial Options
Name:<name-for-the-instance>
Enter a name for your instance. Avoid entering confidential information.
Create in compartment:<your-compartment-name>
Select your compartment. Use the compartment created in the preceding step.
Review the Placement settings.
Take the default values. An availability domain is assigned to you.
The default values are similar to the following:
Availability domain: AD-1
Capacity type: On-demand capacity
Fault domain: Let Oracle choose the best fault domain
Note
For Free Tier, use the Always Free Eligible option for availability domain.
Review the Security settings.
Take the default settings.
The default values are similar to the following:
Shielded instance: Disabled
Confidential computing: Disabled
Review the Image and shape settings. Click Edit.
Note
The following is sample data for an Ampere A1 virtual machine. The actual values might differ.
Keep the default Oracle Linux 8 image.
Click Change Shape.
Select Virtual Machine.
For shape series select Ampere.
Select VM.Standard.A1.Flex the "Always Free" shape.
Select 1 OCPUs.
Click Select Shape.
Selected values are similar to the following:
Image: Oracle Linux 8
Image build:<current-build-date>
Shape: VM.Standard.A1.Flex
OCPU: 1
Memory (GB): 6
Network bandwidth (Gbps): 1
Note
For Free Tier, use Always Free Eligible shape options.
Review the Networking settings. Select the VCN you created in the preceding step. The networking values are similar to the following:
Virtual cloud network: <your-vcn>
Subnet: <pubic-subnet-for-your-vcn>
Launch options: -
DNS record: Yes
Use network security groups to control traffic: No
Assign a public IPv4 address: Yes
Private IPv4 address: Automatically assigned on creation
IPv6 address: Not available
Review the Add SSH keys settings. Take the default values provided by the workflow.
Select the Generate a key pair for me option.
Click Save Private Key and Save Public Key to save the private and public SSH keys for this compute instance.
If you want to use your own SSH keys, select one of the options to provide your public key.
Note
Put your private and public key files in a safe location. You can't retrieve keys again after the compute instance has been created.
Review the Boot volume settings.
Select the Use in-transit encryption setting. Leave the other two settings blank.
Review the Block Volume settings. Take the default values provided by the workflow which does not select any block volumes. You can add block volumes later.
Click Create to create the instance. Provisioning the system might take several minutes.
You have successfully created an Oracle Linux instance to run an Apache Web Server.
4. Enable Internet Access 🔗
The Create a VM Instance wizard automatically creates a VCN for your instance.
You add an ingress rule to your subnet to allow internet connections on port
3000.
Follow these steps to select your VCN's public subnet and add the ingress rule.
Open the navigation menu and click Networking, and then click Virtual Cloud Networks.
Select the VCN you created.
With your new VCN displayed, click <your-subnet-name> subnet link.
The public subnet information is displayed with the Security Lists at the
bottom of the page. A link to the Default Security List for your VCN
is displayed.
Click the Default Security List link.
The default Ingress Rules for your VCN are displayed.
Click Add Ingress Rules.
An Add Ingress Rules dialog is displayed.
Fill in the ingress rule with the following information.
Fill in the ingress rule as follows:
Stateless: Checked
Source Type: CIDR
Source CIDR: 0.0.0.0/0
IP Protocol: TCP
Source port range: (leave-blank)
Destination Port Range: 3000
Description: Allow HTTP connections
Click Add Ingress Rules.
Now HTTP connections are allowed. Your VCN is configured for Node
Express.
You have successfully created an ingress rule that makes your instance available from the
internet.
5. Create a Node Express Application 🔗
Next, set up an Express framework on your Oracle Linux instance and then create and
run a NodeJS application.
Follow these steps to set up your instance and build your application:
Open the navigation menu and click Compute. Under Compute, click Instances.
Click the link to the instance you created in the previous step.
From the Instance Details page look in the Instance Access
section. Copy the public IP address the system created for you. You use
this IP address to connect to your instance.
Open a Terminal or Command Prompt window.
Change into the directory where you stored the ssh encryption
keys you created for this tutorial.
Connect to your instance with this SSH command:
Copy
ssh -i <your-private-key-file> opc@<x.x.x.x>
Since you identified your public key when you created the instance, this
command logs you into your instance. You can now issue
sudo commands to install and start your server.
Enable HTTP connection on port 3000.
Copy
sudo firewall-cmd --permanent --add-port=3000/tcp
Copy
sudo firewall-cmd --reload
Install the latest version of NodeJS.
Copy
sudo yum update
Copy
sudo yum install -y nodejs
Copy
node --version
Create a directory for your application.
Copy
mkdir node-hello-app
Change to the node-hello-app directory.
Copy
cd node-hello-app
Use npm to create a package.json file:
Copy
npm init
Enter information as follows:
name: node-hello-app
version: 1.0.0
description: Node Express Hello application
entry point: app.js (Don't use the default.)
test command: (leave-blank)
git repository: git://github.com/username/repository.git (or
replace with a valid git repository)
keywords: (leave-blank)
author: Example User <username@example.com>
license: UPL-1.0
Preview what you get in package.json.
About to write to /home/opc/node-hello-app/package.json:
{
"name": "node-hello-app",
"version": "1.0.0",
"description": "Node Express Hello application",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/username/repository.git"
},
"author": "Example User <username@example.com>",
"license": "UPL-1.0",
"bugs": {
"url": "https://github.com/username/repository/issues"
},
"homepage": "https://github.com/username/repository#readme"
}
Enter yes to approve your answers.
Install Express and save it in the dependencies list of package.json.
Copy
npm install express --save
Verify that express is added as a dependency in package.json.
Copy
cat package.json
"dependencies": {
"express": "^4.17.1"
}
Create a "Hello, World!" application.
Create the file:
Copy
vi app.js
In the file, input the following text and save the file:
Copy
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function() {
console.log('Hello World app listening on port 3000!');
})
Run the NodeJS program:
Copy
node app.js
Test the application using the command line or a browser:
To test with curl, from a new terminal, connect to your
Ubuntu instance with your SSH keys, and then in the command line enter:
curl -X GET http://localhost:3000
From a browser, connect to the public IP address assigned to your
instance: http://<x.x.x.x>:3000
The Node app returns Hello World! on your instance, or in
your browser.
You have successfully created a local NodeJS application in an Express framework, on
an Oracle Cloud Infrastructure instance.