我如何使用Node.js模块?

时间:2010-09-29 04:28:43

标签: javascript node.js module npm linode

我最近在一个新的Linode盒子上安装了 Node.js ,我认为我处于一种奇怪的情况,我无法使用require()加载任何第三方模块。

我安装了npm并通过npm成功安装了模块,但每当我尝试require其中一个模块(或者只是我自己的同一目录中的一些代码) ), Node.js throwserror说它无法找到模块。

有关为何会发生这种情况的任何想法?

以下是一个示例错误消息:

root@li200-141:/home/mike# npm install sequelize
npm ERR! sudon't!
npm ERR! sudon't! Running npm as root is not recommended!
npm ERR! sudon't! Seriously, don't do this!
npm ERR! sudon't!
npm info it worked if it ends with ok
npm info version 0.2.2
npm info fetch http://registry.npmjs.org/sequelize/-/sequelize@0.4.2.tgz
npm info install sequelize@0.4.2
npm info activate sequelize@0.4.2
npm info build Success: sequelize@0.4.2
npm ok

root@li200-141:/home/mike# node
> var n = require('sequelize').Sequelize
Error: No such native module sequelize
    at requireNative (node.js:83:32)
    at cwdRequire (repl:27:10)
    at [object Context]:1:9
    at Interface.<anonymous> (repl:96:19)
    at Interface.emit (events:27:15)
    at Interface._ttyWrite (readline:295:12)
    at Interface.write (readline:132:30)
    at Stream.<anonymous> (repl:77:9)
    at Stream.emit (events:27:15)
    at IOWatcher.callback (net:489:16)

1 个答案:

答案 0 :(得分:2)

显然,节点v0.2.2中存在一个错误,阻止了必需从REPL正常工作。

尝试将代码放在.js文件中。这对我有用。