I'm using OSX 10.5 and playing around with Nodejs. I've managed to install npm and used it to install a couple of plugins. Well at least the installation says it has worked fine but when I try and load them in I get an error
$npm install htmlparser
Installs ok, then I create a file called test with
var htmlparser = require("node-htmlparser");
and run
$node test.js
I get
var htmlparser = require("node-htmlparser"); node.js:275 throw new Error("Cannot find module '" + request + "'");
I have this in my .bash_profile
file:
export NODE_PATH开发者_开发百科="/usr/local/lib/node"
If I clone the GIT repos at this page and move the file lib/node-htmlparser.js
to ~/.node_libraries
then it works fine.
What is the point of using npm to install anything if I have to move the lib file like this? Am I missing something ?
var htmlparser = require('htmlparser')
should work fine, since they knock the 'node' off the name.
Use the exact name that you use to install the module via NPM.
If you do
npm install htmlparser
Then your syntax for using the module should be
var htmlparser = require("htmlparser");
If that doesn't work, I'd check your npm and/or node install, but with all the details you listed above, that should work fine.
精彩评论