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 |
Tags
- 정규식 문자열 출력
- c++ 정규식
- CentOS7
- centos pyhon 설치
- c3 축 없애기
- c3 초
- 백준
- gcc 업데이트
- python os
- regex_search
- 정규식 활용
- InfluxDB
- influxdb 설치
- snmp
- telegraf
- semanage
- snmp test
- grafana dashboard
- python subprocess
- c3 축 가리기
- c3 step graph
- 정규식 컴파일
- gcc regex
- 1697
- python popen
- g++ 업데이트
- subporcess path
- selinux port 등록
- linux시간으로 변경
- c3 second
Archives
- Today
- Total
리셋 되지 말자
웹서버 만들기 본문
main.js
var http = require('http');
var fs = require('fs');
var app = http.createServer(function(request,response){
var url = request.url;
if(request.url == '/'){
url = '\\index.html';
}
if(request.url == '/favicon.ico'){
response.writeHead(404);
response.end();
return;
}
response.writeHead(200);
console.log(__dirname + url);
response.end(fs.readFileSync(__dirname + url));
});
app.listen(80);
접속화면
콘솔화면
사용자가 요청할 때마다, fs.readFileSync 명령어로 '_dirname + url'경로의 파일을 읽어와서 response.end 명령어로 인자값을 전송해준다.
이게 아파치와의 다른점이다.
프로그래밍적으로 사용자에게 전송할 데이터를 생성한다.
response.end 인자를 'hello world'로 변경했을 때
'NodeJS > 생활코딩' 카테고리의 다른 글
Not found 오류 구현 (0) | 2020.09.09 |
---|---|
파일을 이용해 본문 구현 (0) | 2020.09.08 |
파일 읽기 (0) | 2020.09.08 |
동적 웹 만들기 (0) | 2020.09.08 |
URL (0) | 2020.09.08 |
Comments