尝试使用require('connect').utils.parseCookie与nodejs时找不到模块'connect'

Jos*_* Mc 5 session connect node.js express

我对nodejs等比较陌生.无论如何,我有一个我试图编写的程序,它使用基于此的会话/认证系统:http: //iamtherockstar.com/blog/2012/02/14/nodejs- and-socketio-authentication-all-way-down / 这是基于这个我认为(除了更新的更新版本) http://www.danielbaulig.de/socket-ioexpress/

(它使用Node.js,Express.js,Redis和Sockets.io)无论如何,当我尝试运行我的程序时,我收到此错误:

错误:无法在Module.require(module.js:354:15)的Function._load(module.js:279:25)上的Function._resolveFilename(module.js:332:11)处找到模块'connect'(需要)( module.js:370:17)at Object.(/home/jez/webdir/app1/app.js:62:19)在Module.load的Object..js(module.js:459:10)的Module._compile(module.js:441:26)处( module.js:348:31)在Array.0的Function._load(module.js:308:12)(module.js:479:10)

这对应的代码行是:

var parseCookie = require('connect').utils.parseCookie;
Run Code Online (Sandbox Code Playgroud)

现在在这两个教程中,他们在调用方法parseCookie()之前使用了这一行,但是在他们两个中他们都没有谈到要求'connect'模块,只有我相信的appon连接构建的express模块​​.我的程序与express完美配合,在上述教程中进行调整之前运行正常.

我觉得它可能是对node.js/express/socket.io的最新更新,但该教程仅在几天前写过?,对此的任何帮助将不胜感激!

小智 7

使用cookie模块

utils.parseCookies不再被提供.相反,你可以使用模块cookie

var cookie = require('cookie');
var cookies = cookie.parse('foo=bar; cat=meow; dog=ruff');
Run Code Online (Sandbox Code Playgroud)

https://github.com/shtylman/node-cookie


Lin*_*iel 1

虽然 Express 可以require作为依赖项进行 connect 安装,但我建议您还安装 connect 以便使用该parseCookie实用程序。因此,只需在本地安装 connectnode_modules即可开始!