• Stars
    star
    365
  • Rank 116,851 (Top 3 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated over 10 years ago

Reviews

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

Repository Details

A modular, streaming HTTP server for node.js

Please note: All future development of strata will happen in mach. strata will be maintained for bug fixes, but no new features will be introduced.

Strata is a streaming HTTP server for node.js that is patterned after time-honored web server design principles pioneered in the Python and Ruby communities, namely WSGI and Rack. Using Strata, developers can build highly performant web servers in a powerful, modular style that is easy to maintain and takes full advantage of the streaming capabilities and excellent I/O handling of node.js.

The core Strata distribution consists of four things:

  • A specification (see SPEC) for building applications and middleware
  • A library (see lib) with many useful utilities and middleware to aid developers in the common tasks of building applications that conform to the specification
  • An executable (see bin/strata) for running Strata applications from the command line
  • A user manual (see doc) that contains detailed documentation and code examples

Installation

Install Strata using npm:

$ npm install strata

You are also free to browse or download the source.

Usage

The simplest possible Strata app looks like this:

function app(env, callback) {
  callback(200, {}, "Hello world!");
}

require("strata").run(app);

As you can see from the example above, a Strata "app" is simply a JavaScript function that accepts two arguments: the server environment and a callback. The environment contains all sorts of information about the current request including headers, POST and session data, and much more. The callback is used to send the response. You can read much more about both the environment and the callback in the SPEC.

A slightly more complex application might look something like the following:

var strata = require('strata');

strata.use(strata.commonLogger); // Log requests to the console
strata.use(strata.file, '/path/to/public'); // Serve static files in /path/to/public
strata.use(strata.contentType, 'text/html'); // Default Content-Type to text/html
strata.use(strata.contentLength); // Set the Content-Length automatically
strata.use(strata.sessionCookie, { // Enable cookie-based sessions
  secret: 'session secret string' // Set a session secret for security
});

strata.get('/', function (env, callback) {
  callback(200, {}, 'Hello anonymous!');
});

strata.get('/:username', function (env, callback) {
  var route = env.route;
  callback(200, {}, 'Hello ' + route.username + '!');
});

// Start the server on port 3000
strata.run({ port: 3000 });

There are many more usage examples in the Strata user manual.

Documentation

The Strata user manual is designed to teach you how to get up and running with the framework as quickly as possible. Each chapter of the manual contains documentation about a certain feature of the framework and a code example.

The manual is written in such a way that the topics and examples discussed in higher numbered chapters build upon previous ones. Thus, it is recommended to start with lower numbered chapters when getting started and work your way up to higher ones.

The user manual refers to the SPEC in various places. This document is the canonical reference for the key building blocks of the framework including applications, callbacks, and the Strata environment.

Tests

The test directory contains a comprehensive suite of unit tests for Strata. Use mocha to run them all:

$ mocha test/*-test.js

Or run the tests for a specific module:

$ mocha test/utils-test.js

License

Copyright 2012 Michael Jackson

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 non-infringement. 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.

Acknowledgements

Strata was inspired by similar efforts in the Python and Ruby communities, namely WSGI and Rack. It borrows many code patterns from these libraries, as well as the JSGI project.

Strata's multipart parser is based on the fast parser in the node-formidable project written by Felix Geisendörfer. It is included in Strata under the terms of the MIT license.

My sincere thanks to the authors of each of these libraries for the excellent work they've done and graciously shared.

More Repositories

1

unpkg

The CDN for everything on npm
JavaScript
2,989
star
2

expect

Write better assertions
JavaScript
2,291
star
3

mach

HTTP for JavaScript
JavaScript
812
star
4

http-client

Compose HTTP clients using JavaScript's fetch API
JavaScript
506
star
5

web-starter

Build and deploy a React website quickly on Heroku
JavaScript
417
star
6

citrus

Parsing Expressions for Ruby
Ruby
403
star
7

then-redis

A fast, promise-based Redis client for node.js
JavaScript
315
star
8

shadowbox

A beautiful, versatile lightbox for photos and videos
JavaScript
296
star
9

rollup-plugin-url-resolve

Use URLs in your Rollup imports
JavaScript
136
star
10

react-loop-2019

Notes and code examples from my React Loop 2019 Keynote
JavaScript
116
star
11

resolve-pathname

Resolve URL pathnames using JavaScript
JavaScript
63
star
12

expect-element

Write better assertions for DOM nodes
JavaScript
61
star
13

my-react

An experimental drop-in replacement for React without ES6 classes or "this"
JavaScript
58
star
14

dotfiles

My dotfiles
Vim Script
57
star
15

unpkg-demos

Experiments in how to use unpkg
HTML
54
star
16

history-server

An HTTP server for single-page apps that use the HTML5 history API
JavaScript
52
star
17

rack-accept

HTTP Accept* for Ruby/Rack
Ruby
46
star
18

mint

A small, fast documentation generator for literate-style programming
JavaScript
41
star
19

sinatra-session

Simple, secure sessions for Sinatra
Ruby
38
star
20

firework

A distributed, fault-tolerant work queue for Firebase
JavaScript
38
star
21

s3-thumb-server

Serve thumbnails of images stored on S3 over HTTP
JavaScript
35
star
22

ember-firebase

Firebase bindings for Ember.js
JavaScript
32
star
23

value-equal

Are these two JavaScript values equal?
JavaScript
31
star
24

monterey

Minimal OOP for JavaScript
JavaScript
31
star
25

optionparser

Command-line option parser for PHP
PHP
29
star
26

bufferedstream

A robust stream implementation for node.js and the browser
JavaScript
27
star
27

tree-shaking-react-router

Tree-shaking React Router with webpack 4
JavaScript
25
star
28

icare

A badge to promote empathy in software design, craftsmanship, and maintenance
HTML
25
star
29

react-style

Declarative styling for React components
JavaScript
21
star
30

remix-ssg-example

Small example of how to statically generate a Remix site using wget
TypeScript
19
star
31

dropbox-client

Dropbox API v2 client for JavaScript
JavaScript
17
star
32

bencode

Bencode library for PHP
PHP
15
star
33

reactjsday-2018

Demo + slides from my ReactJS Day 2018 keynote in Verona, Italy
JavaScript
14
star
34

symboltable

A Symbols-only Hash for Ruby
Ruby
13
star
35

broccoli-rev

A Broccoli plugin for adding revision checksums to file names
JavaScript
13
star
36

Fullscreen

A fullscreen sample app for Cocoa with MacRuby
Ruby
12
star
37

yuicompressor

A YUI JavaScript and CSS compressor wrapper for Ruby and JRuby
Ruby
12
star
38

react-router-examples

Code examples for React Router v6
TypeScript
12
star
39

usererror

A base class for JavaScript errors
JavaScript
12
star
40

plural

Pluralization library for PHP
PHP
12
star
41

grand

Generate random data in JavaScript
JavaScript
12
star
42

babel-plugin-import-visitor

Visit all import sources in Babel
JavaScript
10
star
43

then-couchdb

A promise-based CouchDB client for node.js
JavaScript
9
star
44

mwrc2012

Sample code from my talk at MWRC 2012
Ruby
8
star
45

multipart-web-stream

A streaming parser for multipart fetch streams
TypeScript
8
star
46

chatter

A little chat server for #CodeClass
JavaScript
6
star
47

markdown

Markdown as a Service
Ruby
5
star
48

http-client-cookie-jar

Cookie jar middleware for http-client
JavaScript
5
star
49

stratajs.org

The web site for the Strata web framework
JavaScript
5
star
50

form-data-parser

A request.formData() wrapper with pluggable file upload handling
TypeScript
5
star
51

maker

Small library for quickly constructing large segments of HTML in JavaScript
JavaScript
5
star
52

fetch-super-headers

A suite of tools that make it a little more fun to work with Headers
TypeScript
4
star
53

sinatra-spec

Simple specs for Sinatra apps using MiniTest
Ruby
3
star
54

broccoli-select

A Broccoli plugin for selecting files based on glob patterns
JavaScript
3
star
55

jview

A subclass of jQuery.fn for creating views in JavaScript
JavaScript
3
star
56

sequel-factory

Simple, powerful factories for Sequel models
Ruby
3
star
57

describe-property

Define JavaScript object properties quickly with ES5 defaults
JavaScript
3
star
58

mwrc2010

Rack For Web Developers - My presentation from MountainWest RubyConf 2010
Ruby
2
star
59

esbuild-node-builtins-sideeffects

JavaScript
2
star
60

rollup-watch-dir

JavaScript
2
star
61

html5-devconf-may2014

The slides and examples from my presentation at HTML5 DevConf on May 22, 2014
JavaScript
2
star
62

react-router-monorepo-stub

JavaScript
2
star
63

esbuild-empty-file-test

JavaScript
2
star
64

rollup-plugin-babel-bug

JavaScript
2
star
65

rubyconf2010

Grammars, Parsers, and Interpreters. In Ruby. ~ My presentation from RubyConf 2010
Ruby
2
star
66

lazy-file

Lazy, streaming files for JavaScript
TypeScript
2
star
67

jquery-pop

Painless views as models for jQuery
1
star
68

jdrag

Simple drag and drop for jQuery
JavaScript
1
star
69

redemption-from-callback-hell

JavaScript
1
star
70

mjackson.me

JavaScript
1
star
71

file-system

A simple filesystem for JavaScript, based on the File and Streams APIs
TypeScript
1
star
72

JavaScriptObjectsAndPatterns

Some code examples for a class I did for Twitter's HackWeek Q4 2012
JavaScript
1
star
73

mwrc2011

My presentation from MWRC 2011
1
star
74

hoedown2010

My presentation & code for the Ruby Hoedown 2010
1
star