nodejs로 간단한 페이지 띄우기 > BlockChain 자료실

본문 바로가기
사이트 내 전체검색

BlockChain 자료실

nodejs로 간단한 페이지 띄우기

페이지 정보

profile_image
작성자 조선제일검
댓글 0건 조회 1,500회 작성일 22-07-21 00:13

본문

var http = require('http'); // 웹 서버
var fs = require('fs'); // 파일스트림
// 웹 페이지 없을 때 404 response
function send404Response(response){

 response.writeHead(404, {"Content-type":"text/plain"});

response.write("404 Error");
response.end();
}
// 사용자 요구에 응답처리
function onRequest(requestresponse){
if(request.method == 'GET' && request.url == '/'){
response.writeHead(200, {"Content-type":"text/html"});
fs.createReadStream("./index.html").pipe(response);
}else{
send404Response(response);
}
}
// onRequest에 응답할 웹서버 및 포트 3003
http.createServer(onRequest).listen(3003);
console.log("This is Server");

 

 

정상

image (1).png

 

비정상

image (2).png

 

 

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템 / 대표 : 정정모
서울본사 : 서울특별시 강남구 봉은사로 114길 40 홍선빌딩 2층 / tel : 02-6207-1160
대전지사 : 대전광역시 유성구 노은로174 도원프라자 5층 / tel : 042-331-1161

접속자집계

오늘
1,515
어제
1,438
최대
3,935
전체
756,713
Copyright © www.linuxdata.org All rights reserved.