node.js - 在 Node 上安装 Mongoose

标签 node.js mongodb mongoose npm

我正在尝试在 Mac OS X 上安装 Mongoose :

$ sudo npm install -g mongoose
npm http GET https://registry.npmjs.org/mongoose
npm http 304 https://registry.npmjs.org/mongoose
npm http GET https://registry.npmjs.org/hooks/0.2.1
npm http GET https://registry.npmjs.org/mongodb/1.1.11
npm http GET https://registry.npmjs.org/ms/0.1.0
npm http GET https://registry.npmjs.org/sliced/0.0.3
npm http 304 https://registry.npmjs.org/hooks/0.2.1
npm http 304 https://registry.npmjs.org/mongodb/1.1.11
npm http 304 https://registry.npmjs.org/ms/0.1.0
npm http 304 https://registry.npmjs.org/sliced/0.0.3
npm http GET https://registry.npmjs.org/bson/0.1.5
npm http 304 https://registry.npmjs.org/bson/0.1.5

> bson@0.1.5 install /usr/local/lib/node_modules/mongoose/node_modules/mongodb/node_modules/bson
> node install.js || (exit 0)

================================================================================
=                                                                              =
=  Attempting to build bson c++ extension                                      =
=   Windows: no build will be attempted as binaries are prepackaged            =
=   Unix: on failure the package will still install without the C++ extension  =
=                                                                              =
================================================================================
node-gyp clean
node-gyp configure build
  CXX(target) Release/obj.target/bson/ext/bson.o
  SOLINK_MODULE(target) Release/bson.node
  SOLINK_MODULE(target) Release/bson.node: Finished
child process exited with code 0
mongoose@3.3.1 /usr/local/lib/node_modules/mongoose
├── sliced@0.0.3
├── hooks@0.2.1
├── ms@0.1.0
└── mongodb@1.1.11 (bson@0.1.5)
$ node
> require('mongoose');
Error: Cannot find module 'mongoose'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at repl:1:1
    at REPLServer.self.eval (repl.js:111:21)
    at rli.on.e (repl.js:260:20)
    at REPLServer.self.eval (repl.js:118:5)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:93:17)

不应该 require 工作吗?我做错了什么吗?

最佳答案

根据 npm FAQ :

I installed something globally, but I can't require() it

Install it locally.

The global install location is a place for command-line utilities to put their bins in the system PATH. It's not for use with require().

If you require() a module in your code, then that means it's a dependency, and a part of your program. You need to install it locally in your program.

关于node.js - 在 Node 上安装 Mongoose ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13168332/

相关文章:

javascript - Node.js 最高对象值

javascript - Node.js:创建了存储在变量中的 xlsx 文件,但不确定如何保存它

django - Mongoengine 用户认证

ruby-on-rails - 在 Rails 控制台中列出所有 Mongoid 模型

node.js - Mongoose 文本搜索 - 将其行为更改为 AND 操作会减慢速度

node.js - 安装 Mongoose 时出现 NPM 错误 - "Registry returned 404 for GET"

node.js - Ionic应用框架安装在centos服务器中

没有 next 的 Node.js Express 中间件函数

multithreading - 蒙戈 : eliminating race condition on conditional update

node.js - 连接到 MongoDb Atlas 服务器时出错