Gary Dryden
Gary Dryden

Reputation: 11

node.js require("mongodb") throws an exception

I am a newbie to node.js (but 10 years experience with C#) I have the following code

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);

I get this exception:

Error: Cannot find module './node_modules/mongo'

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

I also tried:

var mongo = require("mongo");

Upvotes: 1

Views: 242

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

Try this instead:

var mongodb = require('mongodb');

Upvotes: 1

Related Questions