[英]Including other libraries / files / plugins with nodejs and NPM
I'm using OSX 10.5 and playing around with Nodejs.我正在使用 OSX 10.5 并使用 Nodejs。 I've managed to install npm and used it to install a couple of plugins.我设法安装了 npm 并用它来安装几个插件。 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安装正常,然后我创建了一个名为 test 的文件
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:我的.bash_profile
文件中有这个:
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.如果我在此页面克隆 GIT 存储lib/node-htmlparser.js
并将文件lib/node-htmlparser.js
到~/.node_libraries
那么它就可以正常工作。
What is the point of using npm to install anything if I have to move the lib file like this?如果我必须像这样移动 lib 文件,使用 npm 安装任何东西有什么意义? Am I missing something ?我错过了什么吗?
var htmlparser = require('htmlparser')
应该可以正常工作,因为它们从名称中var htmlparser = require('htmlparser')
了“节点”。
Use the exact name that you use to install the module via NPM.使用您用于通过 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.如果这不起作用,我会检查您的 npm 和/或节点安装,但是根据您上面列出的所有详细信息,应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.