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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4736 | jQuery | 8년 전 | 1562 | ||
| 4735 | jQuery | 8년 전 | 1753 | ||
| 4734 | jQuery | 8년 전 | 1742 | ||
| 4733 | jQuery | 8년 전 | 2037 | ||
| 4732 | jQuery | 8년 전 | 1959 | ||
| 4731 | jQuery | 8년 전 | 1461 | ||
| 4730 | jQuery | 8년 전 | 1920 | ||
| 4729 | PHP |
|
8년 전 | 6906 | |
| 4728 | jQuery | 8년 전 | 2563 | ||
| 4727 | jQuery | 8년 전 | 1612 | ||
| 4726 | jQuery | 8년 전 | 1692 | ||
| 4725 | jQuery | 8년 전 | 1835 | ||
| 4724 | jQuery | 8년 전 | 1313 | ||
| 4723 | jQuery | 8년 전 | 1865 | ||
| 4722 | jQuery | 8년 전 | 1630 | ||
| 4721 | jQuery | 8년 전 | 1919 | ||
| 4720 | jQuery | 8년 전 | 1981 | ||
| 4719 | jQuery | 8년 전 | 1604 | ||
| 4718 | jQuery | 8년 전 | 1610 | ||
| 4717 | jQuery | 8년 전 | 1561 | ||
| 4716 | jQuery | 8년 전 | 1240 | ||
| 4715 | jQuery | 8년 전 | 1397 | ||
| 4714 | jQuery | 8년 전 | 1420 | ||
| 4713 | jQuery | 8년 전 | 1339 | ||
| 4712 | jQuery | 8년 전 | 2230 | ||
| 4711 | jQuery | 8년 전 | 1717 | ||
| 4710 | PHP |
|
8년 전 | 3748 | |
| 4709 | jQuery | 8년 전 | 1630 | ||
| 4708 | jQuery | 8년 전 | 1912 | ||
| 4707 | jQuery | 8년 전 | 1768 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기