general-cluster
v1.0.1
Published
express running on node clusters
Downloads
4
Maintainers
Readme
General Cluster
General Cluster is a utility for running an Express application on a Node Cluster.
- 550 Bytes unzipped
- Express is the only dependency
- Available as an npm package
To learn about using Clusters with Node, please explore the appendix.
Created by Clark Feusier
Installation
General Cluster is available as an npm package, which you can install from the command-line:
npm install general-cluster
Then, require the General Cluster module for use in a desired file:
var GeneralCluster = require('general-cluster');
Basic Usage Example
General Cluster is simple to use.
- Setup your Express application as you normally would
- Instead of calling
listen()
to start your Express server, pass your application to General Cluster, along with the options that you would normally pass to.listen
- Your application will then be served from a node cluster
var GeneralCluster = require('general-cluster'),
express = require('express'),
app = express();
// setup express application configuration and routes, e.g.,
app.get('/*', function(req, res) {
res.send('Hello World');
});
var optionalPort = 3000;
var optionalListeningCb = function() {
console.log("The General is listening on port: " + optionalPort);
};
var optionalHostName = '127.0.0.1';
var optionalBacklog = 511;
// pass configured express app to GeneralCluster to start server
var clusterAppDefaultListenArgs = GeneralCluster(app);
// optionally: pass along a port, hostname, backlog, or callback (see https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback)
// NOTE: the callback will be triggered for each process that binds to the given port
var clusterAppCustomListenArgs = GeneralCluster(app, optionalPort, optionalHostName, optionalBacklog, optionalListeningCb);
Contributing to General Cluster
We welcome contributions, but please read our contribution guidelines before submitting your work. The development requirements and instructions are below.
Development Requirements
- Node 0.10.x
- npm 2.x.x
Installing Development Requirements
Install Node (bundled with npm) using Homebrew:
brew install node
Development Dependencies
- grunt-cli (global install)
- grunt
- grunt-contrib-uglify
Installing Development Dependencies
Install project and development dependencies using npm:
npm install
Building for Deployment
To build src/general-cluster.js
into dist/general-cluster.min.js
, use the following grunt task:
grunt build
License
General Cluster - express running on node clusters
Copyright (C) 2015 Clark Feusier [email protected] - All Rights Reserved
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Appendix
From the Node Cluster documentation:
A single instance of Node runs in a single thread. To take advantage of multi-core systems, one can launch a cluster of Node processes to handle the load. Using Node's cluster allows one to easily create child processes that all share server ports.
Back to Top
© 2015 Clark Feusier. All rights reserved.