Problem running jobs with Node.io
I'm trying to w开发者_运维问答ork through the tutorial jobs for Node.io here. I have no trouble running the built-in modules:
echo "mastercard.com" | node.io -s pagerank
Or:
node.io query "http://www.reddit.com/" a.title
However, when I try my own module:
var nodeio= require('node.io');
exports.job = new nodeio.Job({
input: false,
run: function() {
this.emit('Hello World');
}
});
And try to run it with:
node.io hello
I get this:
ERROR: Failed to load job "hello". Please check that the job exists and compiles correctly.
Debugging gives me this:
DEBUG: {"stack":"Error: Cannot find module 'node.io'\n at Function._resolveFilename (module.js:322:11)\n at Function._load (module.js:267:25)\n at require (module.js:351:19)\n at Object.<anonymous> (/Users/username/Documents/Nodejs/hello.js:1:75)\n at Module._compile (module.js:407:26)\n at Object..js (module.js:413:10)\n at Module.load (module.js:339:31)\n at Function._load (module.js:298:12)\n at require (module.js:351:19)\n at [object Object].loadJob (/opt/local/lib/node_modules/node.io/lib/node.io/processor.js:294:37)","message":"Cannot find module 'node.io'"}
I'm sure I'm doing something stupid. Any thoughts?
Edit: responding to answer below
I've also tried this:
.npm/node.io/0.2.9-4/package/bin/io -s hello.js
And:
node_modules/node.io/bin/node.io -s hello.js
And get this result:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'node.io'
at Function._resolveFilename (module.js:322:11)
at Function._load (module.js:267:25)
at require (module.js:351:19)
at Object.<anonymous> (/Users/thaymore/.npm/node.io/0.2.9-4/package/bin/io:2:1)
at Module._compile (module.js:407:26)
at Object..js (module.js:413:10)
at Module.load (module.js:339:31)
at Function._load (module.js:298:12)
at Array.<anonymous> (module.js:426:10)
at EventEmitter._tickCallback (node.js:126:26)
This is an "feature" of how NPM installs modules including node.io so that it can be found later by node. If you look closely at the stack, the error is node's inability to find node.io itself. The simplest solution is to install to your home directory as the default setup knows how to operate from there. Use "npm install node.io" without the -g option. If you do use -g, be prepared to play with NODE_PATH or several other options, see communication from isaacs. Either way, "node hello" will now work.
Be warned the node community is not afraid of strong opinions, much of which can be treated as noise when choosing the technical solution that best suites your situation, IMHO.
I was able to get it to run like so:
$ npm install node.io
$ node_modules/node.io/bin/node.io -s test.js
Hello World!
Where test.js
is simply:
var nodeio = require('node.io');
exports.job = new nodeio.Job({
input: false,
run: function () {
this.emit('Hello World!');
}
});
I got the same problem and this do the trick for me.
NODE_PATH="$NODE_JS_HOME/lib/node_modules/";
export NODE_PATH
Put the above to either /etc/profile
or ~/.profile
where NODE_JS_HOME
is where you install node.js
edit:
This page http://nodejs.org/api/modules.html also suggests to put the node_modules
folder to the $NODE_PATH
精彩评论