Skip to content

Commit

Permalink
populated a few example files
Browse files Browse the repository at this point in the history
  • Loading branch information
scc36 committed Oct 11, 2014
1 parent 196f08d commit de8ed37
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
17 changes: 16 additions & 1 deletion ex1-printHello.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
// Outputs "Hello World" to the console
console.log("Hello World");
console.log("Hello World");

// Variables + math operation
var number = 1;
number = number + 1;
number += 1;
console.log(number);

// Strings
var text;
text = "How are you doing";
console.log(text);

// Adding strings, and "variable type" changing
text = text + 2;
console.log(text);
14 changes: 12 additions & 2 deletions ex2-functionTest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
// Outputs "Hello World" to the console
console.log("Hello World");
// Raw example expand


function text(phrase) {
console.log(phrase);
}

function myFunction(someFunction, value) {
someFunction(value);
}

myFunction(text, "Hi");
15 changes: 13 additions & 2 deletions ex4-firstServer.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
// Outputs "Hello World" to the console
console.log("Hello World");
// "require" is Node.js feature to "load" libraries
// Library is loaded into variable "http"
var http = require("http");

// Starts a server, takes in a function as an argument
http.createServer(function (req, res) {

// If someone visits the webpage, it returns a webpage with the words "Hello world"
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("This is my website\n");

// Have server listen on port "1337"
}).listen(1337, "127.0.0.1");
18 changes: 18 additions & 0 deletions ex5-serverExpress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Use NPM to install expressjs
//npm install express

// Set express module to variable "express"
var express = require('express');

// Create an "app" variable from the express library
var app = express();

// Add a "route" that leads to the req/res, as seen in Node.js
app.get('/', function(req, res){
res.send("Express powered web page");
});

// Starts up the server
var server = app.listen(1337, function() {

});
File renamed without changes.
2 changes: 0 additions & 2 deletions ex6-serverExpress.js

This file was deleted.

14 changes: 12 additions & 2 deletions ex8-TCPServer.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
// Outputs "Hello World" to the console
console.log("Hello World");
// Load the TCP library and assign it to variable "net"
var net = require("net");

// Start the TCP server
var server = net.createServer(function (socket) {
// If someone connects to the server, just repeat the message
socket.write("You said: \r\n");
socket.pipe(socket);
});

// Have the TCP server listen to port 1337
server.listen(1337, "127.0.0.1");

0 comments on commit de8ed37

Please sign in to comment.