每当我尝试运行 static.js 时,命令:
node static.js
我收到错误:
libpath.exists(filename, function (exists) {
TypeError: undefined is not a function
这是我的 static.js 代码快照:
http.createServer(function (request, response) {
var uri = url.parse(request.url).pathname;
var filename = libpath.join(path, uri);
libpath.exists(filename, function (exists) {
if (!exists) {
response.writeHead(404, {
"Content-Type": "text/plain"
});
response.write("404 Not Found\n");
response.end();
return;
}
我一开始就定义了libpath
var libpath = require('path')
最佳答案
exists 函数未在路径模块中定义,它被定义为文件系统 ('fs') 模块的一部分:
var fs = require('fs');
fs.exists(filename, function (exists) { });
关于javascript - undefined 不是函数 : node error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31641787/