Node.js NodeJS会话错误

Node.js NodeJS会话错误,node.js,Node.js,我不断发现以下错误: /usr/local/lib/node/.npm/connect/1.6.0/package/lib/middleware/session.js:263 var secured = cookie.secure && (req.connection.encrypted || req.connec ^*emphasized text* TypeError: Cannot read prope

我不断发现以下错误:

/usr/local/lib/node/.npm/connect/1.6.0/package/lib/middleware/session.js:263
        var secured = cookie.secure && (req.connection.encrypted || req.connec
                            ^*emphasized text*
TypeError: Cannot read property 'secure' of undefined
    at ServerResponse.writeHead (/usr/local/lib/node/.npm/connect/1.6.0/package/lib/middleware/session.js:263:29)
    at ServerResponse._implicitHeader (http.js:763:8)
    at ServerResponse.end (http.js:628:10)
    at IncomingMessage.next (/usr/local/lib/node/.npm/connect/1.6.0/package/lib/http.js:163:13)
    at ServerResponse.render (/usr/local/lib/node/.npm/express/2.4.3/package/lib/view.js:327:16)
    at /Users/josebalius/Sites/report/report_server.js:102:10
    at /Users/josebalius/Sites/report/report_server.js:23:13
    at Query.<anonymous> (/usr/local/lib/node/.npm/mysql/0.9.1/package/lib/mysql/client.js:119:11)
    at Query.emit (events.js:39:17)
    at Query._handlePacket (/usr/local/lib/node/.npm/mysql/0.9.1/package/lib/mysql/query.js:53:14)

如果你问我的话,你应该提供更多的信息。此外,我认为您应该首先删除外部依赖项(如MySQL等)

发行版

alfred@alfred-laptop:~/node/stackoverflow/6740962$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:    10.10
Codename:   maverick
节点

alfred@alfred-laptop:~/node/stackoverflow/6740962$ node -v
v0.4.9
npm

alfred@alfred-laptop:~/node/stackoverflow/6740962$ npm -v
1.0.15
安装的软件包

alfred@alfred-laptop:~/node/stackoverflow/6740962$ npm ls
/home/alfred
├── connect-redis@1.0.6 
├─┬ everyauth@0.2.16 
│ ├─┬ connect@1.6.0 
│ │ ├── mime@1.2.2 
│ │ └── qs@0.2.0 
│ ├── connect-form@0.2.1  extraneous
│ ├── oauth@0.9.2 
│ ├── openid@0.1.8 
│ ├── restler@0.2.1 
│ └─┬ xml2js@0.1.9 
│   └── sax@0.1.5 
├─┬ express@2.4.3 
│ ├── connect@1.6.0 
│ ├── mime@1.2.2 
│ └── qs@0.2.0 
├── formidable@1.0.2 
├── hiredis@0.1.12 
├── jade@0.13.0 
├── node-expat@1.3.2 
├── node-stringprep@0.0.5 
├─┬ node-xmpp@0.2.9 
│ └── ltx@0.0.5 
├── nodeunit@0.5.1 
├── notifo@0.0.2 
├── openid@0.2.0 
├─┬ optimist@0.2.6 
│ └── wordwrap@0.0.1 
├── recaptcha@1.1.0 
├── redis@0.6.6 
└─┬ socket.io@0.7.7 
  ├── bison@1.1.1  extraneous
  ├── policyfile@0.0.3 
  ├── redis@0.6.0 
  └─┬ socket.io-client@0.7.4 
    └── uglify-js@1.0.3 
代码(基于)

/**
*模块依赖关系。
*/
var express=require('express'),
MemoryStore=require('express')。session.MemoryStore;
var app=express.createServer(
express.logger(),
//session()中间件所需
express.cookieParser(),
//填充:
//-请求会话
//-req.sessionStore
//-req.sessionID(或req.session.id)
session({secret:'keyboard cat',store:newmemorystore({reapInterval:60000*10})})
);
app.get('/',函数(req,res){
变量体=“”;
if(请求会话视图){
++请求会话视图;
}否则{
req.session.views=1;
body+='首次访问?在多个浏览器中查看此页面:)

; } res.send(body+'查看次数'+req.session.views+'次); }); app.listen(3000,'127.0.0.1'); console.log('Express应用程序在端口3000上启动');
卷曲

alfred@alfred-laptop:~/node/stackoverflow/6740962$ curl -v http://localhost:3000* About to connect() to localhost port 3000 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:3000
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/html; charset=utf-8
< Content-Length: 104
< Set-Cookie: connect.sid=63UK2d71YbdrisSQbQoTBcst.ZY%2FiSqeY0g0yCEN%2FX6yUy6zmhjgi7NdPTUo9VTEMfzE; path=/; expires=Tue, 19 Jul 2011 04:29:35 GMT; httpOnly
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
* Closing connection #0
<p>First time visiting? view this page in several browsers :)</p><p>viewed <strong>1</strong> times.</p>
alfred@alfred-笔记本电脑:~/node/stackoverflow/6740962$curl-vhttp://localhost:3000*即将连接()到本地主机端口3000(#0)
*正在尝试::1。。。拒绝连接
*正在尝试127.0.0.1。。。有联系的
*已连接到本地主机(127.0.0.1)端口3000(#0)
>GET/HTTP/1.1
>用户代理:curl/7.21.0(i686 pc linux gnu)libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
>主机:localhost:3000
>接受:*/*
> 
已查看1次


错误似乎来自模块代码,而不是您自己的代码。要么模块有一个bug,要么您不知何故没有正确使用它,并且模块没有优雅地报告这个bug。
/**
 * Module dependencies.
 */
var express     = require('express'),
    MemoryStore = require('express').session.MemoryStore;

var app = express.createServer(
  express.logger(),

  // Required by session() middleware
  express.cookieParser(),

  // Populates:
  //   - req.session
  //   - req.sessionStore
  //   - req.sessionID (or req.session.id)
  express.session({ secret: 'keyboard cat', store: new MemoryStore({ reapInterval: 60000 * 10 })})
);

app.get('/', function(req, res){
  var body = '';
  if (req.session.views) {
    ++req.session.views;
  } else {
    req.session.views = 1;
    body += '<p>First time visiting? view this page in several browsers :)</p>';
  }
  res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');
});

app.listen(3000, '127.0.0.1');
console.log('Express app started on port 3000');
alfred@alfred-laptop:~/node/stackoverflow/6740962$ curl -v http://localhost:3000* About to connect() to localhost port 3000 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: localhost:3000
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/html; charset=utf-8
< Content-Length: 104
< Set-Cookie: connect.sid=63UK2d71YbdrisSQbQoTBcst.ZY%2FiSqeY0g0yCEN%2FX6yUy6zmhjgi7NdPTUo9VTEMfzE; path=/; expires=Tue, 19 Jul 2011 04:29:35 GMT; httpOnly
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
* Closing connection #0
<p>First time visiting? view this page in several browsers :)</p><p>viewed <strong>1</strong> times.</p>