Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정현희
/
WS
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
정현희
2017-04-06 11:53:37 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
46f8f465a5fe149d0d313a05a3fec3b8a4ca0900
46f8f465
1 parent
c707a705
Node.js 실습
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
08_Node.js/app01.js
08_Node.js/app02.js
08_Node.js/app01.js
0 → 100644
View file @
46f8f46
"use strict"
var
http
=
require
(
'http'
);
var
server
=
http
.
createServer
(
function
(
req
,
res
)
{
res
.
writeHeader
(
200
,
{
"Content-Type"
:
"text/plain"
});
res
.
write
(
"I changed port 3000 to 2500! I don't have any problem hahaha"
);
res
.
end
();
});
server
.
listen
(
2500
,
function
()
{
console
.
log
(
"Sever listeining on http://localhost:2500"
);
});
08_Node.js/app02.js
0 → 100644
View file @
46f8f46
"use strict"
var
http
=
require
(
'http'
),
path
=
require
(
'path'
),
url
=
require
(
'url'
),
fs
=
require
(
'fs'
);
var
DOCUMENT_ROOT
=
"../Quiz3/"
;
var
server
=
http
.
createServer
(
function
(
req
,
res
)
{
var
reqPath
=
url
.
parse
(
req
.
url
).
pathname
;
if
(
reqPath
==
"/"
)
{
reqPath
=
"Quiz3.html"
;
}
var
fullPath
=
path
.
join
(
process
.
cwd
(),
DOCUMENT_ROOT
,
reqPath
);
fs
.
readFile
(
fullPath
,
"binary"
,
function
(
err
,
file
)
{
if
(
err
)
{
if
(
err
.
code
==
"ENOENT"
)
{
console
.
log
(
"SEND 404 for "
+
req
.
url
);
res
.
writeHeader
(
404
,
{
"content-type"
:
"text/html"
});
res
.
write
(
"<h1>Not found(/h1)"
);
res
.
end
();
}
else
{
console
.
error
(
"Error"
,
err
);
res
.
writeHeader
(
500
,
{
"content-type"
:
"text/plain"
});
res
.
write
(
err
+
"\n"
);
res
.
end
();
}
}
else
{
console
.
log
(
"SEND 200 for"
+
req
.
url
);
res
.
writeHeader
(
200
);
res
.
write
(
file
,
"binary"
);
res
.
end
();
}
});
});
server
.
listen
(
3000
,
function
()
{
console
.
log
(
"Server listeining on http://localhost:3000"
);
});
Please
register
or
login
to post a comment