기본 콘텐츠로 건너뛰기

node.js fs(file system)모듈 - 이미지와 음악 파일 제공

웹 서버에서는 html페이지뿐만 아니라 음악 파일과 동영상 파일도 다운로드 가능.....

//================52273번 포토에 서버를 생성하고 실행(image 파일 실행)====
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//모듈 추출 file system과 http모듈을 추출하였다
var fs= require('fs');
var http = require('http');
 
//52273번 포트에 서버를 생성하고 실행
http.createServer(function(request, response){
 
    fs.readFile('Chrysanthemun.jpg',function(error,data){
        response.writeHead(200,{'Content''image/jpeg'});
        response.end(data);
});
 
}).listen(52273,function(){
    console.log('Server Running at http://127.0.0.1:52273');
});
 
//52274번 포트에 서버를 생성하고 실행
http.createServer(function(request, response){
 
 
}).listen(52274,function(){
    console.log('Server Running at http://127.0.0.1:52274');
});
cs
//==============================================================

 
content_Tyype속성만 파일 형식에 맞춰서 지정하면 된다 
image 파일 뿐만아니라 음악 파일도 해줄수 있다.
음악 파일이 없는관계로 pass~~

MIME형식의 예
COntent Type   설명
text/plain       기본적인 텍스트
text/css          CSS문서
text/xml          xml문서
image/jpeg      jpg/jpeg그림 파일
image/png      png 그림 파일
video/mpeg     mpeg비디오 파일
audio/mp3      mp3음악 파일

MIME 형식에서 정의한 문자열 
MIME의 문자열 형식은 엄청나게 많다

인터넷에서 MIME TYPE목록을 검색하면 더 많은 종류를 찾아볼 수 있다.

댓글