Node-redis: web_server.js: Cannot find module 'redis'

Created on 9 Nov 2010  ·  19Comments  ·  Source: NodeRedis/node-redis

node v0.3
redis v2.2 antirez git

wfm most test.js

at resolveModuleFilename (node.js:265:13)
at loadModule (node.js:231:20)
at require (node.js:291:14)
at Object. (/Users/jaymini/node_redis/examples/web_server.js:4:20)
at Module._compile (node.js:348:23)
at Object..js (node.js:356:12)
at Module.load (node.js:279:25)
at Array. (node.js:370:24)
at EventEmitter._tickCallback (node.js:42:22)
at node.js:634:9

question

Most helpful comment

all-working now!

had not appreciated that npm used /usr/local/node, before /local/node
had to mv, then hunkydory.. really appreciate webserver.js and others...
so many node projects use jquery, and any other library to hand....

best!

All 19 comments

You need to install the library into your path somehow. I use npm. So from the top level node_redis dir, do:

npm install

It'll install node_redis using the local git repo as the source instead of the npm server's version.

sorry to be dim, but what library?
had various permissions problems with npm,
no doubt to be revisited..
read: api.html#modules
but not clear to me what redis file is to be linked to?

It's worth taking the time to figure out npm. Many node libraries only work properly from npm.

Until you get npm working, you can modify the examples to do:

require("../index");

instead of

require("redis");

result: permission denied

successfully installed npm in ~/local/bin

as per your instruction:
mac-mini:node_redis jaymini$ ~/local/bin/npm install
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info predeactivate [email protected]
npm info deactivate [email protected]
npm info postdeactivate [email protected]
npm info preactivate [email protected]
npm info activate [email protected]
npm info postactivate [email protected]
npm info build Success: [email protected]
npm ok
mac-mini:node_redis jaymini$

but:
mac-mini:examples jaymini$ ~/local/bin/node web_server.js

node.js:63
throw e;
^
Error: Cannot find module 'redis'
at loadModule (node.js:275:15)
at require (node.js:411:14)
at Object. (/Users/jaymini/node_redis/examples/web_server.js:4:20)
at Module._compile (node.js:462:23)
at Module._loadScriptSync (node.js:469:10)
at Module.loadSync (node.js:338:12)
at Object.runMain (node.js:522:24)
at Array. (node.js:756:12)
at EventEmitter._tickCallback (node.js:55:22)
at node.js:772:9
mac-mini:examples jaymini$

the redis aspect is escaping me...

mac-mini:~ jaymini$ ~/local/bin/npm install redis
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info predeactivate [email protected]
npm info deactivate [email protected]
npm info postdeactivate [email protected]
npm info preactivate [email protected]
npm info activate [email protected]
npm info postactivate [email protected]
npm info build Success: [email protected]
npm ok
mac-mini:~ jaymini$ cd node_redis/

when I had tried to install it from within redis:

mac-mini:redis jaymini$ ~/local/bin/npm install
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm ERR! Error installing .
npm ERR! Error: ENOENT, No such file or directory 'package.json'
npm ERR! at node.js:634:9
npm ERR! Report this _entire_ log at http://github.com/isaacs/npm/issues
npm ERR! or email it to [email protected]
npm ERR! Just tweeting a tiny part of the error will not be helpful.
npm not ok
mac-mini:redis jaymini$ cd ~

This looks like more of an npm issue. You can often find isaacs on freenode IRC, channel #node.js. That's often the fastest way to fix npm issues.

If he's not there, sending email to the npm google group address is another way to get support.

as he says there's no package.json in the folder:
https://github.com/isaacs/npm/issues/issue/353

but I'm not clear what to do next...
try a different redis package?

Hmm, that's odd. There is certainly a package.json file in the git repo:

mjr:~/work/node_redis (master)$ ls -l
total 200
-rw-r--r--   1 mjr  staff  15613 Nov  2 15:06 README.md
-rw-r--r--   1 mjr  staff   2078 Sep 20 09:41 bench.js
[email protected]  1 mjr  staff    568 Nov  3 12:46 changelog.md
drwxr-xr-x  12 mjr  staff    408 Nov  3 14:03 examples
[email protected]  1 mjr  staff  28257 Nov  8 16:37 index.js
[email protected]  1 mjr  staff   5421 Nov  2 15:18 multi_bench.js
[email protected]  1 mjr  staff    490 Nov  3 12:44 package.json
[email protected]  1 mjr  staff  33788 Nov  3 12:41 test.js
drwxr-xr-x   4 mjr  staff    136 Sep 24 13:15 tests

And also:

https://github.com/mranney/node_redis/blob/master/package.json

yes, but isn't that in node_redis, not redis?

ie as per issue description: Cannot find module 'redis'
presumably redis module is needed?

The project and repo are called "node_redis", but in npm it is called "redis". This means that you require "redis" and "npm install redis". If you want to install from git, you can check out the repo named "node_redis". From within that "node_redis" directory, you can do "npm install" and it should install properly.

BTW, are you using node and npm from homebrew? The homebrew installation seems to really confuse npm.

no homebrew, but stumped, you'll understand my confusion over redis,
okay so package.json is red herring as nothing to do for redis,
but given that mac-mini:node_redis jaymini$ ~/local/bin/npm install
reported ok, about an hour ago, why is the module not found?

Yeah, that's why I think this is an npm issue. Something about npm on your machine is confused. I suggest removing all traces of npm and node and install both again. Either that, or you can figure out what, exactly, is broken with npm on your computer, but starting over is probably easier.

It should look like this when you install and test:

mjr:~/work/node_redis (master)$ npm install
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info predeactivate [email protected]
npm info deactivate [email protected]
npm info postdeactivate [email protected]
npm info preactivate [email protected]
npm info activate [email protected]
npm info postactivate [email protected]
npm info build Success: [email protected]
npm ok

mjr:~/work/node_redis (master)$ node

require("redis");
{ debug_mode: false,
RedisClient: { [Function: RedisClient] super_: [Function: EventEmitter] },
createClient: [Function],
print: [Function] }

I should add that you probably shouldn't install the git version at all if you aren't making changes. Just get a fresh install of node and npm, and then do:

npm install redis

And you should be able to require("redis").

ok well it's getting late, so in the morning..

will delete and start again!

probably want to fork node_redis,

tx again

OK, cool. Good luck.

all-working now!

had not appreciated that npm used /usr/local/node, before /local/node
had to mv, then hunkydory.. really appreciate webserver.js and others...
so many node projects use jquery, and any other library to hand....

best!

after I enter the command node server.js to make localhost, after I stabbed the command it comes out immediately.
"redis-server" module not found

-------------------------------------Starting server----------------------------------------------------
2019-10-12T08:09:36.456Z - error: Certificate file or key file is missing, falling back to non-SSL mode
2019-10-12T08:09:36.460Z - error: To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh

internal/modules/cjs/loader.js:783
throw err;
^

Error: Cannot find module 'redis-server'
Require stack:

  • /etc/magoware/config/lib/redis.js
  • /etc/magoware/modules/mago/server/policies/mago.server.policy.js
  • /etc/magoware/config/lib/express.js
  • /etc/magoware/config/lib/app.js
  • /etc/magoware/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
    at Function.Module._load (internal/modules/cjs/loader.js:685:27)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/etc/magoware/config/lib/redis.js:2:19)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/etc/magoware/modules/mago/server/policies/mago.server.policy.js:6:13)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/etc/magoware/config/lib/redis.js',
    '/etc/magoware/modules/mago/server/policies/mago.server.policy.js',
    '/etc/magoware/config/lib/express.js',
    '/etc/magoware/config/lib/app.js',
    '/etc/magoware/server.js'
    ]
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

twappworld picture twappworld  ·  7Comments

michaelwittig picture michaelwittig  ·  3Comments

abhaygarg picture abhaygarg  ·  5Comments

adamgajzlerowicz picture adamgajzlerowicz  ·  4Comments

Alchemystic picture Alchemystic  ·  6Comments