Node.js – “未捕获的错误:找不到模块”redis“”
我试图在Node.js中使用Redis作为数据库来构build一个简单的“Twitter”风格的短消息应用程序 (虽然我听说MongoDB可能更容易)…
我发现了一些链接指向我的方向https://github.com/mranney/node_redis,所以我使用Brunch设置了一个新的Node.js项目,并按照指示在我的项目目录中运行以下命令:
npm install redis hiredis
然后,我将auth.js例子中的以下内容添加到了vendor / script.js中
var redis = require("redis"), client = redis.createClient();
但是,当我运行早午餐W – S在控制台中出现以下错误:
Uncaught Error: Cannot find module "redis"
我假设这是与模块没有被列入我的项目,但我不知道从哪里开始。 我补充说
"redis": "latest"
到我的package.json文件,但似乎没有做任何事情。
我也尝试通过运行全局安装redis模块
sudo npm install -g redis
但是还是没有运气。
我还应该补充说我在OS X上安装了redis-server,我可以在terminal上运行它:
$ redis-server [2221] 17 Aug 10:48:42 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf' [2221] 17 Aug 10:48:42 * Server started, Redis version 2.4.13 [2221] 17 Aug 10:48:42 * The server is now ready to accept connections on port 6379 [2221] 17 Aug 10:48:42 - 0 clients connected (0 slaves), 922304 bytes in use [2221] 17 Aug 10:48:47 - 0 clients connected (0 slaves), 922304 bytes in use
我的应用程序目录是一个标准的早午餐安装 –
app config.coffee generators node_modules package.json public README.md test vendor
我究竟做错了什么?
早午餐是html5应用程序汇编程序,而不是node.js,您不能在那里需要节点模块。