DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Node.js Server Configurations

Node.js Server Configurations

Get started developing in Docker with Node.js.

Arslan ud Din Shafiq user avatar by
Arslan ud Din Shafiq
CORE ·
Sep. 20, 19 · Tutorial
Like (1)
Save
Tweet
Share
8.85K Views

Join the DZone community and get the full member experience.

Join For Free

wooden-dock-at-sunset

Get started developing in Docker with Node.js

Node.js is an open-source MIT licensed cross-platform environment for JavaScript, which allows users to execute JS code outside the browser. It has been written in JavaScript, C, and C++. It can be installed on Windows, macOS X, Smart OS, and Linux.

It allows using JavaScript to develop command-line tools. It allows running scripts on the server-side for producing dynamic pages. Rather than using different server-side and client-side languages, it helps you to unify your web application around single programming.

You may also like: What Should I Choose?: Cloud Hosting vs. VPS Hosting.

Node.js is designed to build scalable network applications. Node does not employ any locks, hence, you need not worry about deadlocks. It does not use a common concurrency model where OS threads are employed. Thread-based networking is inefficient and difficult to use.

As it does not use threads, it does not mean you can’t play with multicores — you can use child_process.fork API. It has a cluster module that allows you to share sockets between processes to enable load balancing over cores.

In this tutorial, I will be using Virtual Private Server (VPS) with Ubuntu 16.04 installed on it. I will install and set up Node.js.

Prerequisites

  • You must have a virtual private server (VPS). 
  • ECS must have at least one GB RAM and one Core processor.
  • Register your domain name. If you have already registered a domain, you can update its nameserver records.
  • The domain name must be pointed to your Alibaba Cloud ECS’s IP address.
  • You should set up your server’s hostname.
  • Access to your server via an SSH client.
  • Login as root user and create a user with sudo privileges.

Update Ubuntu System

Before proceeding with the installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges. After execution of this command, you will be prompted to Is this ok? Type ‘y’ and hit Enter key.

Step 1:

sudo apt update && sudo apt upgrade


Install Software-Properties-Common

Software-properties-common package is required to get the supported files for the installation of Docker CE. In order to install software-properties-common package, follow the steps below.

To install software-properties-common execute the command.

sudo apt-get install software-properties-common -y 


Install Apt-Transport-Https:

Apt-transport-https is required for installation of Docker CE. In order to install apt-transport-https, follow the steps below.

To install apt-transport-https execute the command.

# sudo apt-get install apt-transport-https -y 


Install Ca-Certificates

Ca-certificates is required for the installation of Docker CE. In order to install ca-certificates, follow the steps below.

To install ca-certificates execute the command.

sudo apt-get install ca-certificates -y 


Install Curl

Curl is required for installation of Docker CE. In order to install curl, follow the steps below.

To install curl execute the command.

sudo apt-get install curl -y 


Install Docker CE:

To install the Docker community edition, follow the steps below.

Step One

Add GPG key for Docker by executing the command below.

curl -fsSL
https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -


Step Two

Execute the following command to verify the fingerprint of GPG key.

sudo apt-key fingerprint 0EBFCD88


Step Three

Now, add the Docker repository by executing the command below.

sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"


Step Four

Now, update your system by executing command below to load added repository.

sudo apt update


Step Five

Execute the following command to install Docker.

sudo apt install docker-ce


Step Six

Now, add your username to Docker group by executing the command below.

sudo adduser aareez docker 


Close your current shell session and start a new session. Otherwise, you won’t be able to run docker and you may see permission errors.

Step Seven

Execute the following command to check either docker run correctly or not.

docker run hello-world


Install Docker Compose

To download and install Docker compose, follow the steps below.

Step One

Execute the following command to download and install the latest version of docker compose.

sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose


Step Two

Now, set the permissions for file using the command below.

# sudo chmod +x /usr/local/bin/docker-compose


Step Three

Get a list of started containers using the following command.

docker container ls --all


Stop container using port 8080. To do so, get the container id, replace it with 8baab990c424 below, and execute the command.

docker stop 8baab990c424


Pull and Run Node.js

In this tutorial, I will use official image of Node.js for installation on Docker. To download and install Node.js, you will need to execute the following command which will pull latest Nodejs from official docker repository.

docker pull linode/server-node-js


Now, execute the following command to run the docker image.

docker run -d -p 80:3000 linode/server-node-js


Now, you can verify it by accessing your Alibaba Cloud ECS IP address or domain name pointing to that IP address. http://your_domain.tld/test.html.

You will see the following page.

Node.js

Setup Firewalls for HTTP, HTTPS, and Other Required Port:

You will need to open port 80 and 443. To do this, you may read the article on firewalls.

Congratulations!!…here you go…you have successfully installed Node.js for development purposes within Docker.


Related Articles

  • A Look Into Node.js. 
  • How to Build a TCP Application With Node.js on ECS. 

Docker (software) Node.js Command (computing) Virtual private server Database

Published at DZone with permission of Arslan ud Din Shafiq, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Java Concurrency: LockSupport
  • 10 Things to Know When Using SHACL With GraphDB
  • 4 Best dApp Frameworks for First-Time Ethereum Developers
  • Building a REST API With AWS Gateway and Python

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: