Skip to content

fcanela/polyapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PolyApp

npm version Build Status Code Climate Dependencies Dev Dependencies License

Express applications as modules

PolyApp is a simple package which aims to solve two needs:

  • Create Express applications without the hurdle of reimplementing the server logic
  • Easy deploying of containers which have one or more Express modules

PolyApp helps to save time and money. Deploy several modules in the same PolyApp meanwhile you are short of resources. When your demand and resources grow, split easily the modules into more PolyApps so they can handle the traffic.

Table of Contents

Installation

PolyApp is available on npm. To be able to create a container with PolyApp and some modules you need to install the PolyApp dependency first:

npm install --save polyapp

How it works

Poly explained diagram

There are two elements:

  • PolyApp (this package) which runs a instance of Express framework.
  • PolyApp modules which simply exposes a Express router.

You can create a container to deploy as many modules as you want simply following the next steps:

  1. Install PolyApp (using npm) and your modules (with npm, git submodules, placing them on a folder or whatever you prefer)
  2. Require PolyApp and your modules
  3. Create an instance of PolyApp
  4. Include your modules in PolyApp
  5. Start the PolyApp server

Done! You can see steps 2 to 5 in next section.

Usage

Here you have a container example. You simply initialize PolyApp and include as many modules as you want. There is a basic module example following this piece of code.

var PolyApp = require('../polyapp');
var poly = new PolyApp();
poly.port = 8080;

var testModule = require('./test_module');

poly.include(testModule);

poly.start();

Module example

This example is very stupid but it works for illustrating the API. Modules become more interesting when your router exposes full services with multiple endpoints.

var express = require('express');
var OK_STATUS_CODE = 200;

module.exports = function Module(server, options) {
  this.router = express.Router();

  this.router.get('/test', function(req, res, next) {

    res.status(OK_STATUS_CODE).send('It works!');
  });
};

Documentation

Documentation is available here.

Contributing

Bug reports, feature requests and discussion

Feel free to use the GitHub issue tracker to report any bugs or file feature requests. In case you found a bug and have no GitHub account, feel free to email me: fcanela.dev at gmail dot com.

Developing

Pull requests are welcome. I also love technical discussions, so feel free to open a issue on the tracker.

To begin developing clone the GitHub repository and install dependencies with npm install.

The module has some npm scripts which could be useful for developing purpose:

  • npm start watches for changes and runs tests
  • npm run health lints the library and runs tests
  • npm run docs generates the markdown documentation from JsDocs

Features wishlist

  • CORS fast and easy management
  • Cluster
  • API to include middleware

License

Copyright (c) 2016 Francisco Canela. Licensed under the MIT license.

Frequently Asked Questions

Is the code production ready?

This project uses Semver for versioning.

Until the software reaches 1.0.0 I would discourage the use for non-recreative projects.

Why Express instead of Koa?

Koa will break the routes callback API as soon as async/await support is introduced in Node (source). I may migrate PolyApp to Koa when that happens. The later have a lot of features that fits with the project concept.

What about HTTPS?

A reverse proxy (for example, nginx) in front of PolyApp should work. It also makes updating the certificates and configuring SSL a lot easier.

If a reverse proxy does not solve your problem, please, open a issue explaining your case so we can discuss about it.

Isn't this a framework? Why anoooother one?

This project is so simple that I hesitate to call it framework, but as it forces you to certain architecture yes, it could be considered a framework.

Worse, this can be considered a framework on top of another framework. Please, ask your deity for my forgiveness: I created another monster.

My excuse: It solves a problem that I have.

Why this in a world with Docker?

Because deploying a Docker image of each application can take a lot of memory.

I am fan of Docker and microservices architectures. You can have a Docker container with all the services with PolyApp meanwhile you are low of resources or traffic. Later, when you can create images with ease images of PolyApp running only one service each.

About

PolyApp runs express applications as modules

Resources

License

Stars

Watchers

Forks

Packages

No packages published