Node JS 오류 : ENOENT
다음과 함께합니다 : The Node Beginner Book
다른 SO 게시물의 코드로 테스트 한 후 :
var Fs = require('fs');
var dirs = ['tmp'];
var index;
var stats;
for (index = 0; index < dirs.length; ++index)
{
try
{
stats = Fs.lstatSync(dirs[index]);
console.log(dirs[index] + ": is a directory? " + stats.isDirectory());
}
catch (e)
{
console.log(dirs[index] + ": " + e);
}
}
오류가 지속됩니다.
오류 : ENOENT, 해당 파일 또는 디렉토리 'tmp'가 없습니다.
tmp에 대한 권한은 777입니다.
requestHandlers.js
var querystring = require("querystring"),
fs = require("fs");
function start(response, postData) {
console.log("Request handler 'start' was called.");
var body = '<html>'+
'<head>'+
'<meta http-equiv="Content-Type" '+
'content="text/html; charset=UTF-8" />'+
'<style>input{display: block; margin: 1em 0;}</style>'+
'</head>'+
'<body>'+
'<form action="/upload" method="post">'+
'<textarea name="text" rows="20" cols="60"></textarea>'+
'<input type="submit" value="Submit text" />'+
'</form>'+
'</body>'+
'</html>';
response.writeHead(200, {"Content-Type": "text/html"});
response.write(body);
response.end();
}
function upload(response, postData) {
console.log("Request handler 'upload' was called.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("You've sent the text: "+
querystring.parse(postData).text);
response.end();
}
function show(response, postData) {
console.log("Request handler 'show' was called.");
fs.readFile("/tmp/test.jpg", "binary", function(error, file) {
if(error) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(error + "\n");
response.end();
} else {
response.writeHead(200, {"Content-Type": "image/jpg"});
response.write(file, "binary");
response.end();
}
});
}
exports.start = start;
exports.upload = upload;
exports.show = show;
Index.js
var server = require("./server");
var router = require("./router");
var requestHandlers = require("./requestHandlers");
var handle = {}
handle["/"] = requestHandlers.start;
handle["/start"] = requestHandlers.start;
handle["/upload"] = requestHandlers.upload;
handle["/show"] = requestHandlers.show;
server.start(router.route, handle);
약간 당황스럽고 도움을 주시면 감사하겠습니다.
"/tmp/test.jpg"
올바른 경로가 아닙니다.이 경로 /
는 루트 디렉토리 로 시작됩니다 .
유닉스에서 현재 디렉토리의 바로 가기는 다음과 같습니다. .
이 시도 "./tmp/test.jpg"
오류가 발생한 이유를 조금 확장하려면 : 경로 시작 부분의 슬래시는 "파일 시스템의 루트에서 시작하여 주어진 경로를 찾으십시오"를 의미합니다. 슬래시는 "현재 작업 디렉토리에서 시작하여 주어진 경로를 찾으십시오"를 의미합니다.
경로
/tmp/test.jpg
thus translates to looking for the file test.jpg in the tmp folder at the root of the filesystem (e.g. c:\ on windows, / on *nix), instead of the webapp folder. Adding a period (.) in front of the path explicitly changes this to read "start from the current working directory", but is basically the same as leaving the forward slash out completely.
./tmp/test.jpg = tmp/test.jpg
if your tmp folder is relative to the directory where your code is running remove the /
in front of /tmp
.
So you just have tmp/test.jpg
in your code. This worked for me in a similar situation.
You can include a different jade file into your template, that to from a different directory
views/
layout.jade
static/
page.jade
To include the layout file from views dir to static/page.jade
page.jade
extends ../views/layout
change
"/tmp/test.jpg".
to
"./tmp/test.jpg"
use "temp" in lieu of "tmp"
"/temp/test.png"
tmp가 내 컴퓨터에 존재하지 않는 임시 폴더라는 것을 깨달은 후에 작동했지만 내 임시 폴더는 내 임시 폴더였습니다.
///
편집하다:
또한 C : 드라이브에 새 폴더 "tmp"를 만들었고 모든 것이 완벽하게 작동했습니다. 책에서 그 작은 단계를 언급하지 않았을 수도 있습니다.
http://webchat.freenode.net/?channels=node.js 를 확인 하여 node.js 커뮤니티의 일부와 채팅 하십시오.
참고 URL : https://stackoverflow.com/questions/9047094/node-js-error-enoent
'developer tip' 카테고리의 다른 글
Ruby의 다른 괄호는 무엇을 의미합니까? (0) | 2020.09.22 |
---|---|
다른 모듈에서 모듈 변수를 변경하는 방법은 무엇입니까? (0) | 2020.09.22 |
Windows 및 .NET에서 Memcached (0) | 2020.09.22 |
파이썬 3에서 바이트에 대해 b '접두사없이 억제 / 인쇄 (0) | 2020.09.22 |
The specified DSN contains an architecture mismatch between the Driver and Application. JAVA (0) | 2020.09.21 |