8.3.0 • Published 6 years ago

baritone v8.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

#Baritone

A barebone express server.

Baritone is a superset of express. You can use Baritone as if it is an express instance, including all express methods. The only method Baritone overrides is render

##Why?

Because express still has a lot of boiler plate, as well as some common problems to overcome.

###Boiler plate?

  • Config setup
  • Common middleware such as static, compress
  • Starting a server with proper logging

###Common problems?

  • All modules sharing the same config. Discussed in further detail in Baritone.app()
  • Code organization. Discussed in further detail in Baritone.import()

##Quick start

var baritone = require('baritone');

// retrieve a shared baritone (express) instance
var app = baritone.app();

// import the config, middleware, and routes of the base directory and baritone
app.import('.', 'baritone');

// start a server at the default host and port
app.start();

##Static Methods

###Baritone.app()

Retrieves the shared baritone instance, effectively turning express into a singleton. All modules that use baritone.app() will interface with the same underlying express app.

This is different than how invoking express() directly works. Invoking express() always gives you a new express instance. However, this can be unwanted behavior if you want share an express instance among separate modules. Without Baritone, sharing the same express instance was acheived through circular dependencies or globals. Globals are usually frowned upon, and while circular dependencies are supported in node, they can get a little hairy.

##Instance Methods

###baritone.import(...paths)

Attempts to require ./routes, ./middleware, and ./config within each path provided. A path can also be an npm module. For example, in your own app you'll want to import('baritone') to load in baritone's default routes, middleware, and config. Using import('.') will load the routes, middleware, and config from the main app's directory.

This design promotes breaking your app into smaller parts based on purpose. For example, you might have an accounts directory that includes the routes, middleware, and config associated with accounts.

###baritone.start()

Starts a web server. The host and port are retrieved from the config. By default this is 0.0.0.0 and 3000 respectively. You can change these values by importing your own config file or setting PORT and HOST environment variables.

###bartione.pjax(req, res, view)

If the request is an XHR, it responds with the {view: view, data: res.locals}. If the request is not an XHR, it will send the html file set by the html config option. It's up to your client code to retrieve view modules via XHR based on the current URL. Note that this method calls res.send(), effectively ending the request for you.

8.3.0

6 years ago

8.2.0

6 years ago

8.0.0

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.0.2

7 years ago

6.0.1

7 years ago

6.0.0

7 years ago

5.1.0

7 years ago

5.0.0

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.1.5

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago