1.0.1 • Published 4 years ago

cach-server v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Base Node Server

The purpose of this is to provide seamless configuartion of a Node.js server. It is compatible with frameworks such as Express and Koa.

Basic Usage

const createServer = require('base-server');

const server = createServer();

With frameworks

This is also compatible with popular frameworks such as Express and Koa.

Express

const createServer = require('base-server');
const express = require('express');

const app = express();

const server = createServer(app);

Koa

const createServer = require('base-server');
const Koa = require('koa');

const app = new Koa();

const server = createServer(app.callback());

Configuration

createServer(requestListener , options, protocol)

ArgumentTypeDescription
requestListenerFunctionThe request listener that will be used for every request that the server accepts. Required.
optionsObjectThe options object to be provided to the server. If using http as the protocol, the options can be found here. If using https, the options can be found here
loggerObjectAn instance of a logger. Defaults to the console object. Must have at least a log method available.
protocolStringDefines which protocol to be used. Options can be http, http2, or https. If https, you must define SSL information either in the options object or through environment variables.

Environemnt Variables

This receives a lot of it's configuration through the use of environment variables (or command line overrides).

Export nameEnvironment variable nameCommand Line Override(s)Description
PORTprocess.env.PORT--port or -pDefines the port to start the server on
ENVprocess.env.ENV--envDefines the contextual environment that server is being run in. Usually reserved for different internal environments such as development, qa, staging, etc.
NODE_ENVprocess.env.ENV--nodeEnvDefines the Node environment the server is being run in. Usually either development or production and is used for many 3rd party libraries