Skip to content
Browse files

[doc api] Initial commit with 00getting-started and README.md

  • Loading branch information...
0 parents commit 8a752d8cfd4f34611d9e91d08bffe78a3341047a @indexzero committed Feb 1, 2011
Showing with 104 additions and 0 deletions.
  1. +19 −0 LICENSE
  2. +11 −0 README.md
  3. +33 −0 bin/server
  4. +31 −0 lib/00getting-started/pinpoint.js
  5. +10 −0 lib/hello-node.js
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Charlie Robbins
+
+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 NONINFRINGEMENT. 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.
11 README.md
@@ -0,0 +1,11 @@
+# nodejs-intro
+
+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.
+
+#### Author: [Charlie Robbins](http://twitter.com/indexzero)
+
+[0]: http://github.com/cloudhead/journey
+[1]: http://github.com/cloudhead/cradle
+[2]: http://github.com/indexzero/winston
+[3]: http://github.com/substack/node-optimist
+[4]: http://github.com/cloudhead/http-console
33 bin/server
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+
+var sys = require('sys'),
+ path = require('path'),
+ argv = require('optimist').argv;
+
+var help = [
+ "usage: server [options]",
+ "",
+ "Runs the demo pinpoint server at the appropriate stage in development",
+ "",
+ "options:",
+ " -p Port that you want the home server to run on [8000]",
+ " -t, --target Target stage for pinpoint development [00getting-started]",
+ " -h, --help You're staring at it",
+].join('\n');
+
+if (argv.h || argv.help) {
+ return sys.puts(help);
+}
+
+var port = argv.p || 8000,
+ target = argv.t || argv.target || '00getting-started';
+
+//
+// Unshift the target path so that we can require('pinpoint')
+//
+require.paths.unshift(path.join(__dirname, '..', 'lib', target));
+
+var pinpoint = require('pinpoint');
+pinpoint.createServer(port);
+
+sys.puts('Pinpoint demo server listening for ' + target + ' on http://127.0.0.1:' + port);
31 lib/00getting-started/pinpoint.js
@@ -0,0 +1,31 @@
+/*
+ * pinpoint.js: Top-level include for the Pinpoint module.
+ *
+ * (C) 2011 Charlie Robbins
+ * MIT LICENSE
+ *
+ */
+
+var http = require('http'),
+ winston = require('winston');
+
+exports.createServer = function (port) {
+ var server = http.createServer(function (request, response) {
+ var data = '';
+
+ winston.info('Incoming Request', { url: request.url });
+
+ request.on('data', function (chunk) {
+ data += chunk;
+ });
+
+ response.writeHead(501, { 'Content-Type': 'application/json' });
+ response.end(JSON.stringify({ message: 'not implemented' }));
+ });
+
+ if (port) {
+ server.listen(port);
+ }
+
+ return server;
+}
10 lib/hello-node.js
@@ -0,0 +1,10 @@
+// A simple ‘hello world’ server in node.js
+var sys = require('sys'),
+ http = require('http');
+
+http.createServer(function (req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ res.end('hello node');
+}).listen(8000);
+
+sys.puts('Hello node listening on http://127.0.0.1:8000');

0 comments on commit 8a752d8

Please sign in to comment.
Something went wrong with that request. Please try again.