• Stars
    star
    1,257
  • Rank 37,401 (Top 0.8 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Node.js Version of Foreman

Node Foreman Build Status

Node Foreman is a Node.js version of the popular Foreman tool, with a few Node specific changes.

Foreman is a manager for Procfile-based applications. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format.

Install

Install the command line tool

npm install -g foreman

Get usage

nf --help

Deviations from the original Foreman

  • Each worker has an additional automatic environment variable, FOREMAN_WORKER_NAME, that contains the process name and worker number.
    • example: web.1, worker.1

How to Contribute

I encourage anyone and everyone to help. If you have a specific change in mind, open an issue; we can talk about it there.

If you would like to make a code change, go ahead. Fork the repository, open a pull request. Do this early, and talk about the change you want to make. Maybe we can work together on it.

Refactor Refactor Refactor! You are free to add features, or just help clean things up.

Usage

Node Foreman can be run with as little as nf start, as long as npm start has been defined. For more complicated applications you will want to define a Procfile for your various server processes and an .env file to pre-load environmental variables.

Your module directory should end up looking like the following:

List Foreman Directory

Once your Procfile is defined, run your application with nf start:

Start Foreman

Node Foreman always starts in the foreground and expects your applications to do the same. If your processes exit, Node Foreman will assume an error has occurred and shut your application down.

Instead of daemonizing, you should use nf export to ready your application for production.

For more information try any of the following:

$ nf --help
$ nf start --help
$ nf run --help
$ nf export --help

Procfile

The Procfile format is a simple key : command format:

web: node web_server.js
api: node api_server.js
log: node log_server.js

Each line should contain a separate process.

Environmental Variables

Create a .env file to pre-load environmental variables with the format:

MYSQL_NAME=superman
MYSQL_PASS=cryptonite

The equivalent .env file may alternatively be a valid JSON document:

{
    "mysql":{
        "name": "superman",
        "pass": "cryptonite"
    }
}

The above JSON document will be flattened into env variables by concatenating the nested values with an underscore. Environmental variables are passed in fully capitalized.

{
    "mysql":{
        "name": "superman",     # => MYSQL_NAME=superman
        "pass": "cryptonite"    # => MYSQL_PASS=cryptonite
    }
}

There is no need to specify which type of file you wish to use.

The PATH environment variable

The PATH variable is given special treatment and is always read from the environment that the nf command has been executed from, rather than your .env file. To set a different PATH execute nf with the PATH variable set appropriately.

PATH=/opt/foo:/opt/bar:$PATH nf export

Best Practices

Generally you should not check your .env file into version control. The .env file contain only parameters that depend on where the application gets deployed. It should not contain anything related to how the application is deployed.

For example, good candidates for the .env file are MySQL connection information, port bindings, and other passwords.

The Run Command

Tasks or commands that require the environment variables from the .env file can be initiated by using nf run <command>.

Advanced Usage

Node Foreman lets you start multiple jobs of the same type:

$ nf start web=5

18:51:12: web.1     |  Web Server started listening on 0.0.0.0:5000
18:51:12: web.2     |  Web Server started listening on 0.0.0.0:5001
18:51:12: web.3     |  Web Server started listening on 0.0.0.0:5002
18:51:12: web.4     |  Web Server started listening on 0.0.0.0:5003
18:51:12: web.5     |  Web Server started listening on 0.0.0.0:5004

Each job will be started as its own process, receiving a different PORT environmental variable. The port number for processes of the same type will be offset by 1. The port number for processes of different types will be offset by 100.

$ nf start web=2,api=2

18:51:12: web.1     |  Web Server started listening on 0.0.0.0:5000
18:51:12: web.2     |  Web Server started listening on 0.0.0.0:5001
18:51:12: api.1     |  Api Server started listening on 0.0.0.0:5100
18:51:12: api.2     |  Api Server started listening on 0.0.0.0:5101

Export to Production

Node Foreman is designed to be in a development environment, however it can export an Upstart job for use in production. The Upstart file has no dependency on Node Foreman.

$ nf export
Loaded ENV .env File as JSON Format
Wrote  :  ./foreman-web-1.conf
Wrote  :  ./foreman-web.conf
Wrote  :  ./foreman-api-1.conf
Wrote  :  ./foreman-api.conf
Wrote  :  ./foreman-log-1.conf
Wrote  :  ./foreman-log.conf
Wrote  :  ./foreman.conf

You can inspect your upstart files before placing them in the right directory, or have foreman do it for you:

$ sudo nf export -o /etc/init
Loaded ENV .env File as JSON Format
Wrote  :  /etc/init/foreman-api-1.conf
Wrote  :  /etc/init/foreman-web.conf
Wrote  :  /etc/init/foreman-api.conf
Wrote  :  /etc/init/foreman-log.conf
Wrote  :  /etc/init/foreman-log-1.conf
Wrote  :  /etc/init/foreman-web-1.conf
Wrote  :  /etc/init/foreman.conf

Start and stop your jobs with

$ sudo start foreman
Starting foreman... ok
$ sudo stop foreman

The export will occur with whatever environmental variables are listed in the .env file.

systemd Support

This section is beta

Optionally specify a type -t systemd during export for systemd support.

Supervisord Support

You can also use a type -t supervisord during export for supervisord support.

This will generate a APP.conf file grouping the application processes and a APP-PROCESS-N.conf file for each process.

$ nf export --type supervisord
Loaded ENV .env File as JSON Format
Wrote  :  ./foreman-web-1.conf
Wrote  :  ./foreman-api-1.conf
Wrote  :  ./foreman-log-1.conf
Wrote  :  ./foreman.conf

You can start / stop / restart individual processes.

$ sudo supervisorctl start 'foreman:foreman-web-1'
$ sudo supervisorctl stop 'foreman:foreman-web-1'
$ sudo supervisorctl restart 'foreman:foreman-web-1'

Or the entire group of processes

$ sudo supervisorctl start 'foreman:*'
$ sudo supervisorctl stop 'foreman:*'
$ sudo supervisorctl restart 'foreman:*'

Advanced Exports

You can specify the type and number of processes exported using the type=num syntax:

$ nf export web=2,api=2

Use -u <USER> to have the exported job run as USER. Note that if you need to bind to privileged ports, you must start as root. In such a case, we advise you to drop user permissions after binding.

If you want to call your upstart job something other than foreman, use -a <JOBNAME> and manage your jobs with sudo start <JOBNAME>.

Reverse Proxy

Node.js processes are supposed to be stateless. Applications scale by starting multiple processes that either share a socket, or sit behind a load balancer. Node Foreman can help you test the parallel capabilities of your application by spawning multiple processes behind a round-robin proxy.

$ nf start -x 8888 web=5
[OKAY] Starting Proxy Server 8888 -> 5000-5004

Access your application from port 8888 and the connections will be balanced across the servers started from ports 5000 - 5004.

If your application gets its port number from process.env.PORT the proxy setup will happen automatically.

Multiple Reverse Proxies

If you have multiple processes in your Procfile you can start multiple proxies.

$ nf start -x 8888,8080,9090

This will start 3 separate proxies and bind each to a separate process group. Proxies are bound based on their order specified, their order in the Procfile, or by their order on the command line.

$ nf start -x 8888,9999 web,api

Privileged Ports

Node Foreman disallows applications from starting on privileged ports. It does however allow proxies to be bound to lower ports, such as port 80.

If you require access to a privileged port, start Node Foreman with sudo:

$ sudo nf start -x 80 web=5
[OKAY] Starting Proxy Server 80 -> 5000-5004

Your application will then be accessible via port 80, but it will be running as root.

Forward Proxy

Local development and testing has huge advantages, but sometimes one needs to test web applications against their real-world domain name. Editing /etc/hosts is a pain however, and error prone.

Node Foreman can start up an HTTP forward proxy which your browser can route requests through. The forward proxy will intercept requests based on domain name, and route them to the local application.

$ nf start -f 9999 -i nodefly.com
[OKAY] Forward Proxy Started in Port 9999
[OKAY] Intercepting requests to nodefly.com through forward proxy

A forward proxy is useful when testing OAuth, or other external services with application callbacks.

For users with Google Chrome, this can be paired with FelisCatus SwitchyOmega for great results.

More Repositories

1

loopback

LoopBack makes it easy to build modern applications that require complex integrations.
JavaScript
13,228
star
2

microgateway

IBM API Connect Microgateway framework, built on Node.js & Nginx
JavaScript
1,193
star
3

strong-pm

deployer for node applications
JavaScript
998
star
4

loopback-example-access-control

An example demonstrating LoopBack access control mechanisms.
JavaScript
370
star
5

strongloop

StrongLoop: Enterprise Node to Power the API Economy
JavaScript
332
star
6

loopback-example-offline-sync

Offline sync, change tracking, and replication.
JavaScript
286
star
7

zone

Flow control and error handling for Node.js
JavaScript
279
star
8

loopback-example-user-management

LoopBack user management example
JavaScript
189
star
9

loopback-example-passport

LoopBack example for facebook login
HTML
186
star
10

generator-loopback

Yeoman generator that scaffolds out a LoopBack application
JavaScript
158
star
11

loopback-sdk-angular

Service for auto-generating Angular $resource services for LoopBack
JavaScript
155
star
12

loopback-component-passport

LoopBack passport integration to support third party logins and account linking
JavaScript
139
star
13

loopback-component-storage

Storage component for LoopBack.
JavaScript
130
star
14

strong-pubsub

PubSub for Node.js, Browser, Mobile and IoT
JavaScript
129
star
15

loopback-example-database

A tutorial for basic database related features.
JavaScript
120
star
16

strong-arc

StrongLoop Arc has been replaced by API Connect. We recommend Arc users move to the Essentials edition of API Connect. If you have questions, please email [email protected].
JavaScript
114
star
17

loopback-cli

LoopBack CLI tool for creating projects, models and more.
JavaScript
105
star
18

strong-remoting

Communicate between objects in servers, mobile apps, and other servers.
JavaScript
104
star
19

angular-live-set

Build realtime angular apps with html5's Server Sent Events
JavaScript
101
star
20

strong-cluster-control

cluster control module, allowing run-time control and monitoring of cluster
JavaScript
100
star
21

loopback-example-angular

A simple todo list using AngularJS on the client-side and LoopBack on the server-side.
JavaScript
97
star
22

loopback-component-push

Push notification component for LoopBack.
JavaScript
96
star
23

loopback4-example-microservices

Deprecated - please use https://github.com/strongloop/loopback4-example-shopping/tree/master/kubernetes
TypeScript
88
star
24

loopback-getting-started

Getting started example for LoopBack
TSQL
87
star
25

loopback-example-relations

Basic model relations concepts.
JavaScript
80
star
26

loopback-component-explorer

Browse and test your LoopBack app's APIs
JavaScript
71
star
27

loopback-example-ssl

An example to demonstrate how to set up SSL for LoopBack applications
JavaScript
69
star
28

loopback-getting-started-intermediate

JavaScript
68
star
29

loopback-example-facade

Best practices for building scalable Microservices.
JavaScript
67
star
30

strong-supervisor

Application supervisor that automatically adds cluster control and performance monitoring with StrongOps
JavaScript
66
star
31

loopback-boot

Convention-based bootstrapper for LoopBack applications
JavaScript
62
star
32

loopback-component-oauth2

oAuth 2.0 server for LoopBack
JavaScript
62
star
33

strong-agent

Profile, control, and monitor Node.js processes and clusters
JavaScript
61
star
34

strong-mq

MQ API with cluster integration, implemented over various message queues.
JavaScript
56
star
35

loopback-filters

implements LoopBack-style filtering.
JavaScript
55
star
36

modern-syslog

modern-syslog
JavaScript
49
star
37

loopback-example-app-logic

How to add your own business logic in a LoopBack app.
JavaScript
49
star
38

loopback-workspace

Manage a directory of LoopBack projects for a user, team, or organization
JavaScript
49
star
39

loopback-example-angular-live-set

Example of realtime angular app using html5 Server-sent events
JavaScript
48
star
40

strong-build

Build node packages into deployable applications
JavaScript
47
star
41

strong-oracle

Deprecated: Node.js Driver for Oracle databases (Use https://github.com/oracle/node-oracledb instead)
C++
45
star
42

loopback-swagger

LoopBack Swagger Spec Integration
JavaScript
44
star
43

loopback-example-storage

Example for loopback-component-storage.
HTML
43
star
44

supercluster

A module to make it easy to distribute work across multiple network-connected hosts.
JavaScript
30
star
45

loopback-sdk-angular-cli

CLI tools for auto-generating Angular $resource services for LoopBack
JavaScript
29
star
46

gulp-loopback-sdk-angular

gulp plugin for auto-generating Angular $resource services for LoopBack
JavaScript
27
star
47

apiconnect-docker

IBM API Connect on Docker
Shell
26
star
48

strong-globalize

strong-globalize is built on Unicode CLDR and jquery/globalize and implements automatic extraction of strings from JS source code and HTML templates, lint the string resource, machine-translate them in seconds. In runtime, it loads locale and string resource into memory and provides a hook to persistent logging.
JavaScript
25
star
49

loopback-context

Current context for LoopBack applications, based on node-continuation-local-storage
JavaScript
25
star
50

grunt-loopback-sdk-angular

Grunt plugin for auto-generating Angular $resource services for LoopBack
JavaScript
23
star
51

strong-cluster-socket.io-store

Implementation of socket.io store using node's native cluster messaging
JavaScript
23
star
52

loopback-connector-remote

LoopBack remote REST API connector
JavaScript
22
star
53

eslint-config-loopback

LoopBack's ESLint shareable configs.
20
star
54

strongloop-buildpacks

Shell
19
star
55

loopback-connector-swagger

Connect Loopback to a Swagger-compliant API
JavaScript
19
star
56

loopback-multitenant-poc

LoopBack Multitenancy PoC
JavaScript
19
star
57

flow-engine

JavaScript
18
star
58

loopback-example-mixins

Example app demonstrating mixins
JavaScript
17
star
59

eslint-config-strongloop

Baseline eslint configuration for StrongLoop modules
JavaScript
17
star
60

async-tracker

The AsyncTracker API is the JavaScript interface which allows developers to be notified about key events in the lifetime of observed objects and scheduled asynchronous events.
JavaScript
16
star
61

strong-express-metrics

An Express middleware for collecting HTTP statistics.
JavaScript
15
star
62

strong-store-cluster

JavaScript
14
star
63

strong-pubsub-example

Simple example app using strong-pubsub
JavaScript
14
star
64

strong-docs

build documentation sites for your node modules
TypeScript
14
star
65

loopback-connector-jsonrpc

Loopback Connector for JSONRPC
JavaScript
13
star
66

strong-deploy

Deploy nodejs applications
JavaScript
13
star
67

strong-data-uri

Parser and encoder for `data:` URIs
JavaScript
13
star
68

loopback-example-polyglot

Example LoopBack application with polyglot runtimes
JavaScript
13
star
69

loopback-example-push

Push notifications with LoopBack.
JavaScript
12
star
70

strong-task-emitter

JavaScript
11
star
71

strong-pubsub-redis

Redis adapter for strong-pubsub
JavaScript
11
star
72

strong-service-systemd

Generate an systemd service based on provided parameters
JavaScript
11
star
73

strong-cluster-connect-store

Implementation of connect store using node's native cluster messaging
JavaScript
11
star
74

strong-nginx-controller

Nginx controller for Arc
JavaScript
10
star
75

loopback-sandbox

A repository for reproducing LoopBack community issues.
JavaScript
10
star
76

loopback4-example-family-tree

An example LoopBack application to demonstrate OASGraph
TypeScript
10
star
77

strong-log-transformer

A stream filter for performing common log stream transformations like timestamping and joining multi-line messages.
JavaScript
10
star
78

strong-agent-statsd

publish strong-agent metrics to statsd
JavaScript
9
star
79

loopback-connector-db2iseries

Loopback connector for DB2 on iSeries
PLSQL
9
star
80

loopback-multitenancy

WORK IN PROGRESS: Multitenancy component for LoopBack.
JavaScript
9
star
81

strong-pubsub-mqtt

JavaScript
9
star
82

express-example-app

express example app for strong-pm
JavaScript
8
star
83

strong-config-loader

JavaScript
8
star
84

poc-loopback-multitenancy

Proof of concept for multitenancy in LoopBack.
JavaScript
8
star
85

strong-tools

Tools for packaging, releasing, and preparing npm modules
JavaScript
8
star
86

ephemeral-npm

Disposable npm server for testing packages
Shell
8
star
87

dist-paas-buildpack

StrongLoop distributions for PAAS
Shell
7
star
88

strong-service-install

Create/install system service for a given app
JavaScript
7
star
89

strong-service-upstart

Generate an upstart job based on provided parameters
JavaScript
7
star
90

strong-cluster-tls-store

Implementation of TLS session store using node's native cluster messaging
JavaScript
7
star
91

loopback-phase

Phase management for LoopBack applications.
JavaScript
7
star
92

loopback-oracle-installer

Loopback Oracle Installer
JavaScript
7
star
93

strong-module-loader

JavaScript
7
star
94

strong-pubsub-bridge

JavaScript
6
star
95

v4.loopback.io

LoopBack 4 Web Site
HTML
6
star
96

strong-tunnel

Disposable ssh proxy for TCP connections via URL
JavaScript
6
star
97

strong-pubsub-primus

Primus compatibility layer for strong-pubsub.
JavaScript
6
star
98

loopback-example-kv-connectors

LoopBack KeyValue connector examples.
JavaScript
6
star
99

strong-docker-build

Build a Docker image of an app run under strong-supervisor
JavaScript
6
star
100

loopback-oracle-builder

Loopback Oracle Builder
Shell
5
star