Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- go
- grid html
- 장고 하는법
- 후위수식
- flex html
- 풀스택?
- rest graphql
- 데크 구현
- 중위수식
- 중위수식을 후위수식
- grid flex
- 괄호 유효성
- 루비 초보
- golang
- 스택 유효성
- 자료구조 데크
- restapi graphql
- 스택 구현
- 풀스택
- 스택 중위수식
- 괄호 짝 잘맞는지
- 스택 후위수식
- 스택 괄호
- Django tutorial
- 스택 삽입
- 스택 자료구조
- 스택 삭제
- rest gql
- https://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together/219124#219124
- 장고 웹 만들기
Archives
- Today
- Total
donchanee
Node.js 본문
728x90
codeanywhere.com
좋은 사이트이다. 수많은 프리웨어 오픈소스들이 있어서 공부하기 참 좋다.
var http = require('http');var fs = require('fs');var url = require('url');function templateHTML(title, list, body){ return ` <!doctype html> <html> <head> <title>WEB1 - ${title}</title> <meta charset="utf-8"> </head> <body> <h1><a href="/">WEB</a></h1> ${list} ${body} </body> </html> `;}function templateList(filelist){ var list = '<ul>'; var i = 0; while(i < filelist.length){ list = list + `<li><a href="/?id=${filelist[i]}">${filelist[i]}</a></li>`; i = i + 1; } list = list+'</ul>'; return list;}var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var pathname = url.parse(_url, true).pathname; if(pathname === '/'){ if(queryData.id === undefined){ fs.readdir('./data', function(error, filelist){ var title = 'Welcome'; var description = 'Hello, Node.js'; var list = templateList(filelist); var template = templateHTML(title, list, `<h2>${title}</h2>${description}`); response.writeHead(200); response.end(template); }) } else { fs.readdir('./data', function(error, filelist){ fs.readFile(`data/${queryData.id}`, 'utf8', function(err, description){ var title = queryData.id; var list = templateList(filelist); var template = templateHTML(title, list, `<h2>${title}</h2>${description}`); response.writeHead(200); response.end(template); }); }); } } else { response.writeHead(404); response.end('Not found'); }});app.listen(3000);