Skip to content
Newer
Older
100644 178 lines (118 sloc) 9.21 KB
cead1dc @olegp first commit
authored
1 # Common Node
2
a8fcfd6 @olegp added contributing section
authored
3 This package implements a number of [CommonJS](http://www.commonjs.org)
4 proposals on top of [Node.js](http://nodejs.org) using
5 [node-fibers](https://github.com/laverdet/node-fibers). Fibers are used to emulate multi-threading within a single process, allowing one to use a synchronous programming style and as a result:
cead1dc @olegp first commit
authored
6
44b393c @olegp readme tweaks
authored
7 * write fast CRUD webapps that run on Node.js without messy callbacks
5f4e6ff @olegp added platforms
authored
8 * run [webapps, middleware and libraries](https://github.com/olegp/common-node/wiki) written for [RingoJS](http://ringojs.org), [Narwhal](http://narwhaljs.org/), [Akshell](http://www.akshell.com), [Erbix](http://www.erbix.com/), [Wakanda](http://www.wakanda.org/), [v8cgi](http://code.google.com/p/v8cgi/) and [other implementations](http://wiki.commonjs.org/wiki/Implementations)
cead1dc @olegp first commit
authored
9 * mix & match synchronous/asynchronous styles and use the best tool for the job by writing maintainable business logic in a synchronous manner
10 * write concise, legible shell scripts
11
adcc96a @olegp README tweaks
authored
12 The following modules are included:
cead1dc @olegp first commit
authored
13
dcc22ab @olegp fixes #11
authored
14 * assert - [Unit Testing/1.0](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) (available in Node) & a suite for running tests
adcc96a @olegp README tweaks
authored
15 * console - [Console](http://wiki.commonjs.org/wiki/Console) - partial implementation available in Node
4591191 @olegp updated readme
authored
16 * system - [System/1.0](http://wiki.commonjs.org/wiki/System/1.0)
cead1dc @olegp first commit
authored
17 * binary - [Binary/B](http://wiki.commonjs.org/wiki/Binary/B)
18 * io - [IO/A](http://wiki.commonjs.org/wiki/IO/A), including a `ByteArray` backed `MemoryStream`
44b393c @olegp readme tweaks
authored
19 * fs - [Filesystem/A](http://wiki.commonjs.org/wiki/Filesystem/A)
cead1dc @olegp first commit
authored
20 * jsgi - [JSGI 0.3](http://wiki.commonjs.org/wiki/JSGI/Level0/A/Draft2)
21 * httpclient - [HTTP Client/A](http://wiki.commonjs.org/wiki/HTTP_Client/A)
d8986b8 @olegp twitter example added, encourage users to test existing ringo/narhwal
authored
22 * subprocess - methods for launching subprocesses modeled after Ringo (work in progress)
e2e7de8 @olegp socket skeleton
authored
23 * socket - [Sockets/A](http://wiki.commonjs.org/wiki/Sockets/A) (work in progress)
cead1dc @olegp first commit
authored
24
25 ### Installation
26
e256406 @olegp updated bootstrap script
authored
27 If you don't already have them, [install Node version 0.5.2 or later](https://github.com/joyent/node/wiki/Installation) (for Node 0.4.X check out the v0.4 branch of Common Node) and [Node Package Manager](http://npmjs.org). Install `common-node` as a global package:
cead1dc @olegp first commit
authored
28
b49218d @olegp published to npm
authored
29 sudo npm -g install common-node
cead1dc @olegp first commit
authored
30
1afece3 @olegp npm package created
authored
31 Run the "Hello World" example:
cead1dc @olegp first commit
authored
32
e7c7c0b @olegp example launch fix
authored
33 common-node $NODE_PATH/common-node/examples/hello.js
cead1dc @olegp first commit
authored
34
b49218d @olegp published to npm
authored
35 You shouldn't see any output. To test that it's working, make an HTTP request from another prompt:
cead1dc @olegp first commit
authored
36
1afece3 @olegp npm package created
authored
37 curl http://localhost:8080/
cead1dc @olegp first commit
authored
38
39
40 ### Examples
41
c17f26e @olegp fixed broken links
authored
42 A number of examples are available in [common-node/examples](https://github.com/olegp/common-node/tree/master/examples):
cead1dc @olegp first commit
authored
43
44 * `hello.js` - Hello World webapp using JSGI to return a simple text response
45 * `static.js` - streams a static file as a response
46 * `http.js` - makes an HTTP request to another server and returns the result in the response
47 * `sleep.js` - sleeps for one second before returning a response
48 * `spawn.js` - spawns a new fiber which prints to stdout ten seconds after processing a request
d75a3bf @olegp twitter example
authored
49 * `twitter.js` - an example of using Twitter's streaming API, uses HttpClient & TextStream for reading one line at a time
cead1dc @olegp first commit
authored
50
c17f26e @olegp fixed broken links
authored
51 For more usage examples, please refer to the tests in the [common-node/test](https://github.com/olegp/common-node/tree/master/test) directory.
cead1dc @olegp first commit
authored
52
53 ### Documentation
54
9bc3aeb @olegp updated docs link
authored
55 The API reference is available at <http://olegp.github.com/common-node/doc/>
cead1dc @olegp first commit
authored
56
8c77279 @olegp doc generation instructions
authored
57 To generate the documentation, install RingoJS and run:
58
59 ringo-doc -n "Common Node" -s ./lib -d ./doc --file-urls
60
cead1dc @olegp first commit
authored
61 ### Tests
62
04919c5 @olegp node-fibers removed
authored
63 To run the unit tests run:
cead1dc @olegp first commit
authored
64
04919c5 @olegp node-fibers removed
authored
65 node test/all.js
cead1dc @olegp first commit
authored
66
44b393c @olegp readme tweaks
authored
67 You can also run individual tests or sets of tests, for example:
cead1dc @olegp first commit
authored
68
04919c5 @olegp node-fibers removed
authored
69 node test/io.js
70 node test/fs-base/all.js
cead1dc @olegp first commit
authored
71
72 ### Benchmarks
73
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
74 Although `common-node` is optimized for development efficiency rather than performance,
75 a number of benchmarks are included in [common-node/benchmarks](https://github.com/olegp/common-node/tree/master/benchmarks).
76 A `common-node` version, an asynchronous Node version using Connect & a RingoJS version of each benchmark is provided.
77 The scripts are based on the [Ringo/Node benchmark scripts](https://github.com/hns/ringo-node-benchmark), with a couple of additions.
cead1dc @olegp first commit
authored
78
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
79 The benchmarks have the following dependencies:
80
81 * `connect` for Node which can be installed via npm
99a8a57 @olegp markdown errors fixed
authored
82 * `ringo` which can be installed by following the instructions in the [RingoJS repository](https://github.com/ringo/ringojs)
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
83 * `ab` - installed with `sudo apt-get install apache2-utils` on Debian/Ubuntu
84 * `gnuplot` - installed with `sudo apt-get install gnuplot-nox`
85
86 To run them and generate graphs, execute the following command:
87
56df9d3 @olegp running benchmarks
authored
88 cd benchmarks/; ./run; ./graph
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
89
90 This will generate PNG images of the graphs in `benchmarks/results/graphs/`. Some results are provided below:
91
848482b @olegp fixes #6
authored
92 * [buffer-alloc](http://olegp.github.com/common-node/graphs/buffer-alloc.png) - creates a number of byte arrays per request; the difference in performance compared to Node is due to the [array being cleared](https://github.com/olegp/common-node/issues/6)
99a8a57 @olegp markdown errors fixed
authored
93 * [hello-world](http://olegp.github.com/common-node/graphs/hello-world.png) - returns a dynamically generated string
94 * [no-alloc](http://olegp.github.com/common-node/graphs/no-alloc.png)
95 * [parse-json](http://olegp.github.com/common-node/graphs/parse-json.png)
ac0fef6 @olegp added set timeout benchmark
authored
96 * [set-timeout](http://olegp.github.com/common-node/graphs/set-timeout.png) - sleep for 100ms before returning a response
99a8a57 @olegp markdown errors fixed
authored
97 * [static-file](http://olegp.github.com/common-node/graphs/static-file.png) - returns a file served from the file system
98 * [string-alloc](http://olegp.github.com/common-node/graphs/string-alloc.png)
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
99
848482b @olegp fixes #6
authored
100 As you can see from the results and given no profiling or optimization work has been done so far, there's room for improvement.
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
101 Any patches or suggestions on how to improve performance would be greatly appreciated.
a8fcfd6 @olegp added contributing section
authored
102
fdcf32f @olegp added embedding section
authored
103 ### Embedding
104
04919c5 @olegp node-fibers removed
authored
105 To use the package in your existing app, you will need to:
fdcf32f @olegp added embedding section
authored
106
04919c5 @olegp node-fibers removed
authored
107 * run your app with `node` instead of `common-node`
f47d75f @olegp updated embedding instructions
authored
108 * change the way in which you require modules from `var io = require('io');` to `var io = require('common-node').io;` or update your NODE_PATH to include `common-node/lib` (see `bin/common-node` for an example)
e256406 @olegp updated bootstrap script
authored
109
fa856a4 @olegp fixed markdown syntax in example
authored
110 For example the following modified version of `examples/http.js` can be run directly via `node http.js`
e256406 @olegp updated bootstrap script
authored
111
da9d696 @olegp udpated example
authored
112 var HttpClient = require('common-node').httpclient.HttpClient;
fa856a4 @olegp fixed markdown syntax in example
authored
113
114 exports.app = function(request) {
115 return {
116 status: 200,
117 headers: {},
118 body: new HttpClient({
119 url: 'http://google.com'
120 }).finish().body
121 };
122 };
123
124 if(require.main == module) {
125 require('common-node').run(exports);
126 }
fdcf32f @olegp added embedding section
authored
127
a8fcfd6 @olegp added contributing section
authored
128 ### Contributing
129
34f7847 @olegp install from git instructions
authored
130 To contribute to this project, you can start by trying to run the tests on your system and posting any failures on the issue tracker. It is advised that you use the version in master for doing this, which you can install via:
131
132 npm install -g https://github.com/olegp/common-node/tarball/master
a8fcfd6 @olegp added contributing section
authored
133
134 If you run into any issues along the way, whether related to using this library
3f98e1f @olegp platform list expanded
authored
135 in your own project or to the documentation, please post your comments on the [issue tracker](https://github.com/olegp/common-node/issues/). The tracker is also a great place to contribute ideas and find out what needs doing.
a8fcfd6 @olegp added contributing section
authored
136
d8986b8 @olegp twitter example added, encourage users to test existing ringo/narhwal
authored
137 If you're coming from Ringo or Narwhal, please try running the tests for some of your existing packages. If the tests pass and the packages is compatible with Common Node, feel free to add it to the [wiki](https://github.com/olegp/common-node/wiki).
138
fae6021 @olegp TODO link
authored
139 To find specific issues not listed on the tracker, you can run the following command from inside the `common-node` directory.
a8fcfd6 @olegp added contributing section
authored
140
141 grep 'TODO' lib/*
142
44b393c @olegp readme tweaks
authored
143 To contribute code: fork the project, make and commit your changes and send a pull request.
cead1dc @olegp first commit
authored
144
fae6021 @olegp TODO link
authored
145 A number of higher level goals, such as descriptions of packages that would complement Common Node are listed on the [TODO wiki page](https://github.com/olegp/common-node/wiki/TODO).
146
cead1dc @olegp first commit
authored
147 ### Acknowledgements
148
149 * Hannes Wallnoefer and others from [RingoJS](http://ringojs.org) - this project uses a number of its tests & the Ringo code was used as a starting point for some modules
150 * Kris Kowal, Tom Robinson, Isaac Schlueter for [Narwhal](http://narwhaljs.org/) - this project used a number of its modules as a starting point and some methods in e.g. Binary have been copied as is
950f757 @olegp license added
authored
151 * everybody on the [CommonJS](http://groups.google.com/group/commonjs) mailing list
152
153 ### License
154
155 (The MIT License)
156
157 Copyright (c) 2011 Oleg Podsechin
158
159 Permission is hereby granted, free of charge, to any person obtaining
160 a copy of this software and associated documentation files (the
161 'Software'), to deal in the Software without restriction, including
162 without limitation the rights to use, copy, modify, merge, publish,
163 distribute, sublicense, and/or sell copies of the Software, and to
164 permit persons to whom the Software is furnished to do so, subject to
165 the following conditions:
166
167 The above copyright notice and this permission notice shall be
168 included in all copies or substantial portions of the Software.
169
170 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
171 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
172 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
173 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
174 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
175 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
176 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
177
Something went wrong with that request. Please try again.