Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
# nothing really here | ||
# hellonode! | ||
the simplest possible http server hello world example in node | ||
|
||
## this is a demo node.js application that starts up an http server. useful to have when you need to stub out tests for spawning http servers from git urls and npm packages :-) | ||
## features | ||
|
||
- Example package.json | ||
- Starts up simple httpServer with helloworld | ||
|
||
## installation | ||
|
||
git clone git://github.com/Marak/hellonode.git | ||
cd hellonode | ||
node server.js | ||
|
||
Now you should have a listening node.js http server running on port 80 | ||
|
||
## the code | ||
|
||
// requires node's http module | ||
var http = require('http'); | ||
|
||
// creates a new httpServer instance | ||
http.createServer(function (req, res) { | ||
// ^^ this is the callback, or request handler for the httpServer | ||
// respond to the browser, write some headers so the | ||
// browser knows what type of content we are sending | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
// write some content to the browser that your user will see | ||
res.write('hello, i know nodejitsu.') | ||
// close the response | ||
res.end(); | ||
}).listen(80); // the server will listen on port 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
{ | ||
"name": "hellonode", | ||
"description": "demo node.js application that starts up an http server", | ||
"version": "0.1.0", | ||
"author": "Marak Squires", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/Marak/hellonode.git" | ||
}, | ||
"subdomain": "hellonode", | ||
"scripts": { | ||
"start":"server.js" | ||
"start": "server.js" | ||
}, | ||
"engine": [ "node >=0.1.90" ] | ||
} | ||
"version": "0.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
var sys = require('sys'), | ||
http = require('http'); | ||
var http = require('http'); | ||
|
||
http.createServer(function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.write('hello, i know nodejitsu! write more stuff') | ||
res.write('hello, i know nodejitsu.') | ||
res.end(); | ||
}).listen(80); | ||
|
||
/* server started */ | ||
sys.puts('> hello world running on port 80'); | ||
}).listen(80); |