File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ var http = require ( 'http' ) ;
2
+
3
+ var port = 8080 ;
4
+ var host = '0.0.0.0' ;
5
+
6
+ var server = http . createServer ( ) ;
7
+
8
+ // Start the HTTP server, start listening for requests
9
+ server . listen ( port , host , function ( error ) {
10
+ if ( error ) {
11
+ console . log ( error ) ;
12
+ } else {
13
+ console . log ( 'api listening on port' , port ) ;
14
+ }
15
+ } ) ;
16
+
17
+ // Create a event handler for "request"
18
+ server . on ( 'request' , function ( request , response ) {
19
+ console . log ( 'New http request received' , request . url ) ;
20
+ response . write ( '<html><head></head><body><h1>Hello world</h1></body></html>' ) ;
21
+ response . end ( ) ;
22
+ } ) ;
23
+
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments