nodejs 파일 읽기
Node.js 파일 시스템 모듈
파일 서버로서의 Node.js
Node.js 파일 시스템 모듈을 사용하면 컴퓨터의 파일 시스템을 사용하여 작업 할 수 있습니다.
파일 시스템 모듈을 포함하려면 다음 require()방법을 사용하십시오 .
var fs = require('fs');
파일 시스템 모듈의 일반적인 사용 :
- 파일 읽기
- 파일 만들기
- 파일 업데이트
- 파일 삭제
- 파일 이름 바꾸기
파일 읽기
이 fs.readFile()방법은 컴퓨터의 파일을 읽는 데 사용됩니다.
Node.js와 같은 폴더에 다음 HTML 파일이 있다고 가정합니다.
demofile1.html
<html>
<body>
<h1>My Header</h1>
<p>My paragraph.</p>
</body>
</html>
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
fs.readFile('demofile1.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}).listen(8080);
위의 코드를 "demo_readfile.js"파일에 저장하고 파일을 시작하십시오.
demo_readfile.js 시작 :
C:\Users\Your Name>node demo_readfile.js
댓글 1개
terrorboy
6년 전
원문 링크도 함께 표시해주시면 안될까요?
게시판에 글이 들어가니 가독성이..
게시판에 글이 들어가니 가독성이..
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2617 | ||
| 4945 | node.js | 6년 전 | 2389 | ||
| 4944 | node.js | 6년 전 | 2526 | ||
| 4943 | node.js | 6년 전 | 2278 | ||
| 4942 | node.js | 6년 전 | 2260 | ||
| 4941 | node.js | 6년 전 | 2724 | ||
| 4940 | node.js | 6년 전 | 1872 | ||
| 4939 | node.js | 6년 전 | 1999 | ||
| 4938 | node.js | 6년 전 | 2461 | ||
| 4937 | node.js | 6년 전 | 2255 | ||
| 4936 | node.js | 6년 전 | 2327 | ||
| 4935 | node.js | 6년 전 | 2144 | ||
| 4934 | node.js | 6년 전 | 2453 | ||
| 4933 | node.js | 6년 전 | 2254 | ||
| 4932 | node.js | 6년 전 | 2692 | ||
| 4931 | node.js | 6년 전 | 2078 | ||
| 4930 | node.js | 6년 전 | 2004 | ||
| 4929 | node.js | 6년 전 | 8641 | ||
| 4928 | node.js | 6년 전 | 3758 | ||
| 4927 | node.js | 6년 전 | 2399 | ||
| 4926 | node.js | 6년 전 | 2509 | ||
| 4925 | node.js | 6년 전 | 2093 | ||
| 4924 | node.js | 6년 전 | 3380 | ||
| 4923 | node.js | 6년 전 | 2231 | ||
| 4922 | node.js | 6년 전 | 1997 | ||
| 4921 | node.js | 6년 전 | 2051 | ||
| 4920 | node.js | 6년 전 | 1770 | ||
| 4919 | node.js | 6년 전 | 2043 | ||
| 4918 | node.js | 6년 전 | 2184 | ||
| 4917 | node.js | 6년 전 | 2402 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기