paint-brush
Step-By-Step Tutorial To Deploy A Distributed Node.js App At The Edgeby@section
739 reads
739 reads

Step-By-Step Tutorial To Deploy A Distributed Node.js App At The Edge

by SectionNovember 15th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Step-By-Step Tutorial To Deploy A Distributed Node.js App At The Edge uses Section's Edge Compute Platform. Deploying your app closer to your end users reduces latency - shown to be up to 7x faster than Cloud. The Section platform expects that you have run both of these commands before you can deploy your app. You will need to sign up for a Section account and set up the SSL certificate for your website. We will now take the example NuxtJS app that we set up in the previous step and deploy it across the Section network.

Company Mentioned

Mention Thumbnail
featured image - Step-By-Step Tutorial To Deploy A Distributed Node.js App At The Edge
Section HackerNoon profile picture

In this tutorial, we are going to demonstrate how to deploy a distributed Node.js app at the Edge using Section's Edge Compute Platform.

Before we get into the how-to's, you may be wondering why you would want to deploy your app at the Edge vs. a typical Cloud deployment. Well, the biggest reason is speed. Deploying your app closer to your end users reduces latency - shown to be up to 7x faster than Cloud. Aside from speed, there are additional security and scalability benefits that can be achieved by deploying your applications (or portions of your application) at the Edge.

Let's do some coding!

At the end of this tutorial, you will have:

  • A website running as a subdomain at
    section.dev
  • SSL certificates for your website
  • Working knowledge of the
    sectionctl
    CLI tool to deploy changes to your app

Prerequisites:

  • You will need to sign up for a Section account
  • Text editor
  • Terminal app
  • Install the
    sectionctl
    CLI tool (instructions provided below).
  • Node.js version 10.14 or later

Step 1: Set up the Section CLI tool

After you have created your Section account, download the latest release of

sectionctl
from Github.

On Linux, this looks like:

wget https://github.com/section/sectionctl/releases/download/v1.1.0/sectionctl-v1.1.0-linux-amd64.tar.gz
tar zxvf sectionctl-v1.1.0-linux-amd64.tar.gz

Next, you'll need to place the executable on your path and make sure that it can be executed.

On Linux, this looks like:

mv sectionctl /usr/local/bin/sectionctl
chmod +x /usr/local/bin/sectionctl

Next, configure authentication by running:

sectionctl login

When prompted, enter your Section username and password, and security store them where

sectionctl
can find them.

The Section CLI is now configured and ready to use.

Step 2: Set up your Node.js application

For this tutorial, we are going to set up a simple NuxtJS app to deploy on Section's Edge.

Note: If you are on Windows, we recommend downloading Git for Windows and use Git Bash that comes with it, which supports the UNIX-specific commands in this tutorial.

Open your terminal,

cd
into the directory where you wish to create your app, and clone the demo app:

git clone https://github.com/section/nodejs-example

Now,

cd
into your newly created directory called
nodejs-example
:

cd nodejs-example

Next, pull down the dependencies and build your app by running:

npm install
npm run-script build

Note: The Section platform expects that you have run both of these commands before you can deploy your app.

Start your app's development server on port 8080 by running:

npm run-script start

You can check to see if it's working by opening http://localhost:8080 in your browser.

Step 3: Deploy your Node.js app

We will now take the example NuxtJS app that we set up in the previous step and deploy it across Section's Edge network.

First, locate your account ID using the following command:

sectionctl accounts

This should return an output similar to this:

| ACCOUNT ID | ACCOUNT NAME                      |
|------------|-----------------------------------|
| 1335       | g9ts24tx7gm8n12b2evf3.section.dev |

Use the number value in the account ID column to list your applications:

sectionctl apps list --account-id 1335

The output should look similar to this:

| APP ID |    APP NAME                       |
|--------|-----------------------------------|
| 7171   | g9ts24tx7gm8n12b2evf3.section.dev |

Note: The app name was automatically generated when you signed up. You will need this name for the final steps.

Next, we will set up the SSL certificate for your domain. (This is a free service provided by Section.)

Run the following command, substituting your account ID and app name:

sectionctl certs renew --account-id 1335 --hostname g9ts24tx7gm8n12b2evf3.section.dev

Wait a few minutes while Section uploads and deploys your Node.js app across the Edge network.

You can now view your app running on Section by navigating to your provided app name.

Congratulations! You have deployed your Node.js app on Section's Edge. Be sure to check out the Traffic Monitor in your Section Console to see how your app is performing across the globe.

To learn more, check out Section Docs and/or contact a Section Edge Solutions Expert.

Previously published at https://www.section.io/docs/getting-started/tutorials/launching-a-nodejs-app/