easy-express-server

Easy expressjs predefined and configurable server.

Usage no npm install needed!

<script type="module">
  import easyExpressServer from 'https://cdn.skypack.dev/easy-express-server';
</script>

README

Easy expressjs predefined and configurable server.

Install

npm -g install easy-express-server

Usage

EES is a CLI tool for prepare and start an expressjs aplication based on a json properties file.

ees -P ./propertiesFile.json

If you don't pass -P option, EES will attepmt to use 'ees_properties.json' from the current dir.

Properties

  • app: A single name for the app.
  • main: Main path from where all other paths will be relative to. By default, the current dir.
  • server: An object with two availables properties: http and https.
    • http: An object with a listen propertie in which you can define port,hostname and backlog that configures an http server for the expressjs app.
    • https: An object with a listen propertie such as http. Also you can define https options:
      • key: Path to the certificate key.
      • cert: Path to the certificate.
      • pfx: Path to the pfx file. If you define this file, key and cert will be ignored.
  • static: An object to configure the static service. You must define the main path for the static files. Also you can define static settings (See express documentation).
  • loaders: Array of loaders configuration. Each middleware function will be loaded by requiring all module files who match each configuration.
    • main: The main path in wich the loader searches for modules. Also, this is the "root" path for these modules.
    • method: Method name that will be used to load each middleware function. All available methods are:
    • config: All modules loaded with config method must be a function that receives the expressjs application. Use this method if you want to add specific configuration programatically.
      • locals: All modules loaded with locals method must be a json file. Each propertie of json file will be set to app.locals object.
      • express functions: All modules loaded with the following methods must export the middleware function or an array of middleware functions. If dirouting is set to false, you must allways exports an array in wich the first index should be the endpoint route. Supported functions are:
        • all
        • delete
        • engine
        • get
        • post
        • put
        • render
        • use
        • ws (If websockets are enabled)
    • filter: A regular expression used to filter each file that will be required.For more info see EML documentation.
    • depth: Number indicating how deep in the main path you want to load. For more info see EML documentation.
    • dirouting: Set to true if you want to register each endpoint relative to the main path. By default, false.
      Then, if you main path is "/home/dev/api":
      /home/dev/api/index.js -> this module will be loaded in "/" endpoint, because for the loader "/home/dev/api" is te root.
      /home/dev/api/login/login.js -> this module will be loaded in "/login" endpoint.
      /home/dev/api/content/content.js -> this module will be loaded in "/content" endpoint and so on...
  • ws: Options object passed to WebSocketServer constructor. See express-ws. The websocket instance will be stored in app.wsInstance.

See examples!!