gpt4 book ai didi

javascript - 500 类型错误 : Not a string or buffer in express. js,node.js

转载 作者:行者123 更新时间:2023-11-30 23:04:40 25 4
gpt4 key购买 nike

我正在使用 node.js,express.jsmysql2 创建一个身份验证页面。网页中的 Useridpassword 出现在 app.post('/login',...) 中。但是当我发布用户名和密码,出现以下错误:

Express
500 TypeError: Not a string or buffer
at Hash.update (crypto.js:209:17)
at app.get.capture.responce (c:\wamp\www\Guru Gobind Singh Ji Site\app.js:455:52)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:164:37)
at param (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:138:11)
at pass (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:145:5)
at nextRoute (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:100:7)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:167:11)
at app.get.responseJSON (c:\wamp\www\Guru Gobind Singh Ji Site\app.js:33:3)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:164:37)
at param (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:138:11)Express
500 TypeError: Not a string or buffer
at Hash.update (crypto.js:209:17)
at app.get.capture.responce (c:\wamp\www\Guru Gobind Singh Ji Site\app.js:455:52)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:164:37)
at param (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:138:11)
at pass (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:145:5)
at nextRoute (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:100:7)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:167:11)
at app.get.responseJSON (c:\wamp\www\Guru Gobind Singh Ji Site\app.js:33:3)
at callbacks (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:164:37)
at param (c:\wamp\www\Guru Gobind Singh Ji
Site\node_modules\express\lib\router\index.js:138:11)

这是代码...

var application_root = __dirname,
express = require("express"),
mysql = require('mysql2'),
path = require("path");

var app = express();

var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123',
database: "bbsbec"
});

app.use(express.bodyParser());
app.use(express.cookieParser('shhhh, very secret'));
app.use(express.session());

// Config

app.configure(function () {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(application_root, "public")));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});

app.post('/login', function(request, response) {
var username = request.body.name;
var password = request.body.passwords;
var hash = require('crypto').createHash('md5').update(password).digest("hex");
console.log(username);
console.log(hash);
var user;
var pword;
connection.query('SELECT * from pass', function(err, rows) {
user = rows[0].userid;
pword= rows[0].password;
if(username == user && password == pword)
{
request.session.regenerate(function(){
request.session.user = username;
response.redirect('http://127.0.0.1/restricted');
});
}
else {
response.redirect('http://127.0.0.1/AdminPanel/error.html');
}
});
});

app.get('/logout', function(request, response){
request.session.destroy(function(){
response.redirect('http://127.0.0.1/Admin-Panel/index.html');
});
});

app.get('/restricted', restrict, function(request, response){
var capture = { responce: 'pass'};
catchjson = JSON.stringify(capture);
response.redirect('http://127.0.0.1/Admin-Panel/admin.html');
});

// Launch server
app.listen(5000, function(){
console.log('Server running...');
});

最佳答案

我正面临我的 nodejs 服务器中的问题。我发现通过删除以下部分:

app.listen(5000, function(){
console.log('Server running...');
});

服务器将正常工作。

关于javascript - 500 类型错误 : Not a string or buffer in express. js,node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22387694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com