Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 183 lines (121 sloc) 9.842 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
172fd1e @olegp readme updated
authored
12 If you have a spare 20 minutes, you can also check out [this presentation](http://www.slideshare.net/olegp/server-side-javascript-going-all-the-way](audio included).
13
adcc96a @olegp README tweaks
authored
14 The following modules are included:
cead1dc @olegp first commit
authored
15
dcc22ab @olegp fixes #11
authored
16 * 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
17 * console - [Console](http://wiki.commonjs.org/wiki/Console) - partial implementation available in Node
4591191 @olegp updated readme
authored
18 * system - [System/1.0](http://wiki.commonjs.org/wiki/System/1.0)
cead1dc @olegp first commit
authored
19 * binary - [Binary/B](http://wiki.commonjs.org/wiki/Binary/B)
20 * io - [IO/A](http://wiki.commonjs.org/wiki/IO/A), including a `ByteArray` backed `MemoryStream`
44b393c @olegp readme tweaks
authored
21 * fs - [Filesystem/A](http://wiki.commonjs.org/wiki/Filesystem/A)
cead1dc @olegp first commit
authored
22 * jsgi - [JSGI 0.3](http://wiki.commonjs.org/wiki/JSGI/Level0/A/Draft2)
23 * 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
24 * subprocess - methods for launching subprocesses modeled after Ringo (work in progress)
e2e7de8 @olegp socket skeleton
authored
25 * socket - [Sockets/A](http://wiki.commonjs.org/wiki/Sockets/A) (work in progress)
cead1dc @olegp first commit
authored
26
27 ### Installation
28
75b11db @olegp Edited README.md via GitHub
authored
29 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). It's also highly recommended that you have your $NODE_PATH variable [set correctly](https://github.com/olegp/common-node/issues/20).
83a5901 @olegp Edited README.md via GitHub
authored
30
31 Install `common-node` as a global package:
cead1dc @olegp first commit
authored
32
b49218d @olegp published to npm
authored
33 sudo npm -g install common-node
cead1dc @olegp first commit
authored
34
1afece3 @olegp npm package created
authored
35 Run the "Hello World" example:
cead1dc @olegp first commit
authored
36
e7c7c0b @olegp example launch fix
authored
37 common-node $NODE_PATH/common-node/examples/hello.js
cead1dc @olegp first commit
authored
38
b49218d @olegp published to npm
authored
39 You shouldn't see any output. To test that it's working, make an HTTP request from another prompt:
cead1dc @olegp first commit
authored
40
1afece3 @olegp npm package created
authored
41 curl http://localhost:8080/
cead1dc @olegp first commit
authored
42
43
44 ### Examples
45
c17f26e @olegp fixed broken links
authored
46 A number of examples are available in [common-node/examples](https://github.com/olegp/common-node/tree/master/examples):
cead1dc @olegp first commit
authored
47
48 * `hello.js` - Hello World webapp using JSGI to return a simple text response
49 * `static.js` - streams a static file as a response
50 * `http.js` - makes an HTTP request to another server and returns the result in the response
51 * `sleep.js` - sleeps for one second before returning a response
52 * `spawn.js` - spawns a new fiber which prints to stdout ten seconds after processing a request
d75a3bf @olegp twitter example
authored
53 * `twitter.js` - an example of using Twitter's streaming API, uses HttpClient & TextStream for reading one line at a time
99d2ce6 @olegp Edited README.md via GitHub
authored
54 * `chat.js` - Telnet chat server, compare this to an [async implementation](http://pastebin.com/Rhbbr6Tf)
cead1dc @olegp first commit
authored
55
c17f26e @olegp fixed broken links
authored
56 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
57
58 ### Documentation
59
9bc3aeb @olegp updated docs link
authored
60 The API reference is available at <http://olegp.github.com/common-node/doc/>
cead1dc @olegp first commit
authored
61
8c77279 @olegp doc generation instructions
authored
62 To generate the documentation, install RingoJS and run:
63
64 ringo-doc -n "Common Node" -s ./lib -d ./doc --file-urls
65
cead1dc @olegp first commit
authored
66 ### Tests
67
04919c5 @olegp node-fibers removed
authored
68 To run the unit tests run:
cead1dc @olegp first commit
authored
69
04919c5 @olegp node-fibers removed
authored
70 node test/all.js
cead1dc @olegp first commit
authored
71
44b393c @olegp readme tweaks
authored
72 You can also run individual tests or sets of tests, for example:
cead1dc @olegp first commit
authored
73
04919c5 @olegp node-fibers removed
authored
74 node test/io.js
75 node test/fs-base/all.js
cead1dc @olegp first commit
authored
76
77 ### Benchmarks
78
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
79 Although `common-node` is optimized for development efficiency rather than performance,
80 a number of benchmarks are included in [common-node/benchmarks](https://github.com/olegp/common-node/tree/master/benchmarks).
81 A `common-node` version, an asynchronous Node version using Connect & a RingoJS version of each benchmark is provided.
82 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
83
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
84 The benchmarks have the following dependencies:
85
86 * `connect` for Node which can be installed via npm
99a8a57 @olegp markdown errors fixed
authored
87 * `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
88 * `ab` - installed with `sudo apt-get install apache2-utils` on Debian/Ubuntu
89 * `gnuplot` - installed with `sudo apt-get install gnuplot-nox`
90
91 To run them and generate graphs, execute the following command:
92
56df9d3 @olegp running benchmarks
authored
93 cd benchmarks/; ./run; ./graph
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
94
95 This will generate PNG images of the graphs in `benchmarks/results/graphs/`. Some results are provided below:
96
848482b @olegp fixes #6
authored
97 * [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
98 * [hello-world](http://olegp.github.com/common-node/graphs/hello-world.png) - returns a dynamically generated string
99 * [no-alloc](http://olegp.github.com/common-node/graphs/no-alloc.png)
100 * [parse-json](http://olegp.github.com/common-node/graphs/parse-json.png)
ac0fef6 @olegp added set timeout benchmark
authored
101 * [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
102 * [static-file](http://olegp.github.com/common-node/graphs/static-file.png) - returns a file served from the file system
103 * [string-alloc](http://olegp.github.com/common-node/graphs/string-alloc.png)
e448d12 @olegp benchmark graphs added to readme, minor benchmark fixes
authored
104
848482b @olegp fixes #6
authored
105 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
106 Any patches or suggestions on how to improve performance would be greatly appreciated.
a8fcfd6 @olegp added contributing section
authored
107
fdcf32f @olegp added embedding section
authored
108 ### Embedding
109
04919c5 @olegp node-fibers removed
authored
110 To use the package in your existing app, you will need to:
fdcf32f @olegp added embedding section
authored
111
04919c5 @olegp node-fibers removed
authored
112 * run your app with `node` instead of `common-node`
f47d75f @olegp updated embedding instructions
authored
113 * 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
114
fa856a4 @olegp fixed markdown syntax in example
authored
115 For example the following modified version of `examples/http.js` can be run directly via `node http.js`
e256406 @olegp updated bootstrap script
authored
116
da9d696 @olegp udpated example
authored
117 var HttpClient = require('common-node').httpclient.HttpClient;
fa856a4 @olegp fixed markdown syntax in example
authored
118
119 exports.app = function(request) {
120 return {
121 status: 200,
122 headers: {},
123 body: new HttpClient({
124 url: 'http://google.com'
125 }).finish().body
126 };
127 };
128
129 if(require.main == module) {
130 require('common-node').run(exports);
131 }
fdcf32f @olegp added embedding section
authored
132
a8fcfd6 @olegp added contributing section
authored
133 ### Contributing
134
34f7847 @olegp install from git instructions
authored
135 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:
136
137 npm install -g https://github.com/olegp/common-node/tarball/master
a8fcfd6 @olegp added contributing section
authored
138
139 If you run into any issues along the way, whether related to using this library
3f98e1f @olegp platform list expanded
authored
140 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
141
1a1fcb9 @olegp Merge branch 'master' of git@github.com:olegp/common-node.git
authored
142 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 package is compatible with Common Node, feel free to add it to the [wiki](https://github.com/olegp/common-node/wiki).
d8986b8 @olegp twitter example added, encourage users to test existing ringo/narhwal
authored
143
fae6021 @olegp TODO link
authored
144 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
145
146 grep 'TODO' lib/*
147
44b393c @olegp readme tweaks
authored
148 To contribute code: fork the project, make and commit your changes and send a pull request.
cead1dc @olegp first commit
authored
149
fae6021 @olegp TODO link
authored
150 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).
151
cead1dc @olegp first commit
authored
152 ### Acknowledgements
153
154 * 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
155 * 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
156 * everybody on the [CommonJS](http://groups.google.com/group/commonjs) mailing list
157
158 ### License
159
160 (The MIT License)
161
162 Copyright (c) 2011 Oleg Podsechin
163
164 Permission is hereby granted, free of charge, to any person obtaining
165 a copy of this software and associated documentation files (the
166 'Software'), to deal in the Software without restriction, including
167 without limitation the rights to use, copy, modify, merge, publish,
168 distribute, sublicense, and/or sell copies of the Software, and to
169 permit persons to whom the Software is furnished to do so, subject to
170 the following conditions:
171
172 The above copyright notice and this permission notice shall be
173 included in all copies or substantial portions of the Software.
174
175 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
176 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
177 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
178 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
179 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
180 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
181 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
182
Something went wrong with that request. Please try again.