TAGS :Viewed: 14 - Published at: a few seconds ago

[ Node.js - "Uncaught Error: Cannot find module "redis"" ]

I'm trying to build a simple "Twitter" style short messaging app in Node.js which uses Redis as the database (although I've heard that MongoDB might be easier)...

I have found a few links that point me in the direction of https://github.com/mranney/node_redis so I set up a new Node.js project using Brunch and ran the following in my project directory as instructed:

npm install redis hiredis

I then added the following from the auth.js example to vendor/script.js

var redis  = require("redis"),
client = redis.createClient();

However when I run brunch w -s I get the following error in the console:

Uncaught Error: Cannot find module "redis"

I'm assuming that it's something to do with modules not being included into my project but I'm not really sure where to start. I added

"redis": "latest"

to my package.json file but that doesn't appear to do anything.

I also tried to install the redis module globally by running

sudo npm install -g redis

But still no luck.

I should also add that I have redis-server installed on OS X, and I can run it in the 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

My application directory is a standard brunch install -

app
config.coffee
generators
node_modules
package.json
public
README.md
test
vendor

What am I doing wrong?

Answer 1


Brunch is html5 application assembler, not node.js, you can’t require node modules there.