node.js require(“mongodb”)抛出异常

时间:2012-11-04 14:32:13

标签: node.js mongodb

我是node.js的新手(但有10年C#经验) 我有以下代码

var http = require("http");
var url = require("url");
var path = require('path');
var fs = require("fs");
var express = require("express");
var mongo = require("./node_modules/mongo");
var Server = mongo.Server;
var Db = mongo.Db;
var server = new Server('localhost', 27017, {auto_reconnect: true});
var db = new Db('mydb', server);

我得到了这个例外:

  

错误:无法找到模块' ./ node_modules / mongo'

at Function.Module._resolveFilename (module.js:338:15)

我也尝试过:

var mongo = require("mongo");

1 个答案:

答案 0 :(得分:1)

请改为尝试:

var mongodb = require('mongodb');