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

Skip to content

Commit c8c9f07

Browse files
authored
Merge pull request HackYourFuture#1 from HackYourFuture/week1
Week1
2 parents a74cc2a + 955ea66 commit c8c9f07

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

week1/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## This week homework
2+
3+
Assignment:
4+
Create a http server that listens to requests
5+
http://localhost:8080/status -->
6+
http://localhost:8080/add -->
7+
http://localhost:8080/subtract -->
8+
9+
Reading
10+
Callbacks
11+
modules, require
12+
http, http listen
13+
refresh on command line

week1/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// To run this file: node index.js
2+
// Then in your browser: http://localhost:8080
3+
var http = require('http');
4+
5+
var port = 8080;
6+
7+
var server = http.createServer();
8+
9+
// Start the HTTP server, start listening for requests
10+
server.listen(port, function(error) {
11+
if (error) {
12+
console.log(error);
13+
} else {
14+
console.log('api listening on port', port);
15+
}
16+
});
17+
18+
// Create a event handler for "request"
19+
// this is an alternative way
20+
server.on('request', function(request, response) {
21+
console.log('New http request received', request.url);
22+
response.setHeader('content-type', 'text/html');
23+
response.write('<html><head></head><body><h1>Hello world</h1></body></html>');
24+
response.end();
25+
});

week1/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "week1",
3+
"version": "1.0.0",
4+
"description": "Week 1 homework",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/HackYourFuture/Node.js.git"
12+
},
13+
"keywords": [
14+
"nodejs"
15+
],
16+
"author": "Erol",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/HackYourFuture/Node.js/issues"
20+
},
21+
"homepage": "https://github.com/HackYourFuture/Node.js#readme"
22+
}

0 commit comments

Comments
 (0)