Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a752d8

Browse files
committed
[doc api] Initial commit with 00getting-started and README.md
0 parents  commit 8a752d8

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2010 Charlie Robbins
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# nodejs-intro
2+
3+
My introduction presentation to node.js along with sample code at various stages of building a simple RESTful web service with journey, cradle, winston, optimist, and http-console.
4+
5+
#### Author: [Charlie Robbins](http://twitter.com/indexzero)
6+
7+
[0]: http://github.com/cloudhead/journey
8+
[1]: http://github.com/cloudhead/cradle
9+
[2]: http://github.com/indexzero/winston
10+
[3]: http://github.com/substack/node-optimist
11+
[4]: http://github.com/cloudhead/http-console

bin/server

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
var sys = require('sys'),
4+
path = require('path'),
5+
argv = require('optimist').argv;
6+
7+
var help = [
8+
"usage: server [options]",
9+
"",
10+
"Runs the demo pinpoint server at the appropriate stage in development",
11+
"",
12+
"options:",
13+
" -p Port that you want the home server to run on [8000]",
14+
" -t, --target Target stage for pinpoint development [00getting-started]",
15+
" -h, --help You're staring at it",
16+
].join('\n');
17+
18+
if (argv.h || argv.help) {
19+
return sys.puts(help);
20+
}
21+
22+
var port = argv.p || 8000,
23+
target = argv.t || argv.target || '00getting-started';
24+
25+
//
26+
// Unshift the target path so that we can require('pinpoint')
27+
//
28+
require.paths.unshift(path.join(__dirname, '..', 'lib', target));
29+
30+
var pinpoint = require('pinpoint');
31+
pinpoint.createServer(port);
32+
33+
sys.puts('Pinpoint demo server listening for ' + target + ' on http://127.0.0.1:' + port);

lib/00getting-started/pinpoint.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* pinpoint.js: Top-level include for the Pinpoint module.
3+
*
4+
* (C) 2011 Charlie Robbins
5+
* MIT LICENSE
6+
*
7+
*/
8+
9+
var http = require('http'),
10+
winston = require('winston');
11+
12+
exports.createServer = function (port) {
13+
var server = http.createServer(function (request, response) {
14+
var data = '';
15+
16+
winston.info('Incoming Request', { url: request.url });
17+
18+
request.on('data', function (chunk) {
19+
data += chunk;
20+
});
21+
22+
response.writeHead(501, { 'Content-Type': 'application/json' });
23+
response.end(JSON.stringify({ message: 'not implemented' }));
24+
});
25+
26+
if (port) {
27+
server.listen(port);
28+
}
29+
30+
return server;
31+
}

lib/hello-node.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// A simple ‘hello world’ server in node.js
2+
var sys = require('sys'),
3+
http = require('http');
4+
5+
http.createServer(function (req, res) {
6+
res.writeHead(200, { 'Content-Type': 'text/plain' });
7+
res.end('hello node');
8+
}).listen(8000);
9+
10+
sys.puts('Hello node listening on http://127.0.0.1:8000');

0 commit comments

Comments
 (0)