Edgio

Node.js Connector

Node.js Connector lets you build and deploy your project to Edgio for any framework that is not listed under our directly supported frameworks.

Prerequisites

Setup requires:

Install the Edgio CLI

If you have not already done so, install the Edgio CLI.
Bash
1npm i -g @edgio/cli@latest

Using Node.js Connector

To use the Node.js Connector with your project, you’ll first need to initialize your project using the Edgio CLI with the following:
Bash
1edgio init
By default Edgio will try to recognize the underlying framework when you run the edgio init command. However, if the framework you are using does not fall within the list of supported frameworks, you will be prompted to select the type of project you want to set up:
Bash
1WARNING: No framework detected. You can still use Edgio; however, we need more information about your project.
2? What kind of project do you want to set up?
3❯ Edgio Sites (Web-app hosting)
4 Edgio Performance (CDN-as-code)
Choose Edgio Sites (Web-app hosting) from the list of options to prepare the project for Node.js Connector.
Next, you will be prompted to enter more information specific to your project and framework:
  • What is the build directory for server files of your app? (Leave blank if not applicable) - This is the output directory where all of your framework’s build files are located. A common build directory is dist, but this may vary depending on your framework.
  • What is the path of the entry file (relative to the build directory) of your app? (Leave blank if not applicable) - This is the entry file of your app. A common entry file is index.js, but this may vary depending on your framework.
  • What is static files directory of your app? (Leave blank if not applicable) - This is the directory where all of your static files are located. A common static files directory is public, but this may vary depending on your framework.
  • What is the environment variable name for the port your app server listens to? (Leave blank if not applicable) - This is the name of the environment variable for setting the port the project will run on. Note: many frameworks use PORT as the default environment variable name for port. Edgio will pass the port value to your app via the environment variable specified here.
  • Please specify the build command (if available) - This is the build command of your app. The build command will be used when you run the edgio build command.
  • Please specify the dev server command (if available) - This is the command to run the local development server of your app. The dev command will be used when you run the edgio dev command.
  • Please specify a message or timeout value (in seconds) to wait until the dev server is ready - This is the message (or timeout seconds) that will be used to determine when the local development server is ready to accept requests. For example, the development server may print a message like Server is listening on port 3000 when it is ready to accept requests. In this case, you could enter listening on as the dev ready message. If the development server does not print a message when it is ready, you can enter the number of seconds to wait before the development server is ready to accept requests.
plain
1✔ What is the build directory for server files of your app? (Leave blank if not applicable) … dist
2✔ What is the path of the entry file (relative to the build directory) of your app? (Leave blank if not applicable) … index.js
3✔ What is the static files directory of your app? (Leave blank if not applicable) … public
4✔ What is the environment variable name for the port your app server listens to? (Leave blank if not applicable) … PORT
5✔ Please specify the build command (if available) … custom_fw build
6✔ Please specify the dev server command (if available) … custom_fw dev
7✔ Please specify a message or timeout value (in seconds) to wait until the dev server is ready › 5
When initialization process is finished, Edgio will automatically add all of the required dependencies and files to your project. These include:
  • The @edgio/core package
  • The @edgio/cli package
  • The @edgio/connectors package
  • edgio.config.js - Contains various configuration options for Edgio including the connector configuration.
  • routes.js - A default routes file that sends all requests to the underlying framework. Update this file to add caching or proxy some URLs to a different origin.

Routing

The default routes.js file created by edgio init sends all requests to your framework’s server.
JavaScript
1// This file was added by edgio init.
2// You should commit this file to source control.
3
4const { Router } = require('@edgio/core/router');
5const { connectorRoutes } = require('@edgio/connectors');
6
7export default new Router()
8 // automatically adds all routes from the Node.js connector
9 .use(connectorRoutes)
See Routes for information on defining routes, caching, and more.

Running Locally

To test your app locally, run:
Bash
1edgio dev
You can do a production build of your app and test it locally using:
Bash
1edgio build && edgio run --production
Setting --production runs your app exactly as it will be when deployed to the Edgio cloud.

Deploy to Edgio

Deploy your app to the Sites by running the following commands in your project’s root directory:
Bash
1edgio deploy
Your initial CDN-as-code deployment will generate system-defined origin configurations along with those defined within your edgio.config.js. Learn more about system-defined origins.
See Deployments for more information.

Node.js Connector Configuration

After you initialize your project with the edgio init command, Edgio will create a edgio.config.js file in your project’s root directory. In the edgio.config.js file you can configure your Node.js Connector.
JavaScriptedgio.config.js
1{
2 /* rest of the config */
3
4 "nodejsConnector": {
5 "buildFolder" : "dist",
6 "entryFile": "index.js",
7 "envPort": "PORT",
8 "buildCommand": "npm run build",
9 "devCommand": "npm run dev",
10 "devReadyMessageOrTimeout": 5,
11 }
12}
In the nodejsConnector object you can configure the following options:
  • buildFolder - The build output folder of your app.
  • entryFile - The entry file of your app.
  • staticFolder - The static files folder of your app.
  • envPort - The environment variable name for port (if it is available). Default value is PORT. Note: many frameworks use PORT as the default environment variable name for port. Edgio will pass the port value to your app via the environment variable specified here
  • buildCommand - The build command of your app. Default value is an empty string. This command is used when you run edgio build command.
  • devCommand - The dev command of your app. Default value is an empty string. This command is used when you run edgio dev command.
  • devReadyMessageOrTimeout - A message to be printed when dev server is ready or timeout value in seconds to wait. Default value is 0.

Connector

This connector is not built for a specific framework. It is used as a fallback for frameworks that are not directly supported by Edgio. See Connectors for more information.