[英]Node.js Authentication TypeError: object is not a function
I'm currently following a tutorial on how to build a simple HTTP authentication system in Node.js. 我目前正在学习如何在Node.js中构建一个简单的HTTP身份验证系统的教程 。 I've followed pretty much all the steps of the tutorial just as it says, yet when I try to run it, I always get this error:
TypeError: object is not a function
我已经按照教程中的所有步骤进行了操作,但是当我尝试运行它时,我总是得到这个错误:
TypeError: object is not a function
Here's the code from the tutorial: (The error occurs on line 3) 这是教程中的代码:(错误发生在第3行)
var http = require("http");
var auth = require("http-auth");
var digest = auth({
authRealm: "Private area",
authFile: __dirname + "/htpasswd",
authType: "digest"
});
var server = http.createServer(function(request, response) {
digest.apply(request, response, function(username) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello " + username);
response.end();
});
});
server.listen(80);
console.log("Server is listening");
Thanks in advance! 提前致谢! Sorry if this question is quite stupid, I'm new to Node.js.
对不起,如果这个问题非常愚蠢,我是Node.js的新手。 :P
:P
try using: 尝试使用:
var basic = auth.basic({
authRealm: "Private area",
authFile: __dirname + "/htpasswd",
authType: "digest"
});
for the assignment of the basic
variable. 用于分配
basic
变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.