Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoClient TypeError
    primarykey
    data
    text
    <p>I am a NodeJS newbie and JS can-kicker trying out DI for the first time. Here are the questions I looked at before deciding to ask mine, since they show the same error: <a href="https://stackoverflow.com/questions/7358455/undefined-is-not-a-function-in-nodejs-expressjs">[1]</a><a href="https://stackoverflow.com/questions/13131626/typeerror-undefined-is-not-a-function-in-nodejs">[2]</a></p> <p>Running my entry point yields:</p> <pre><code>this.client = new MongoClient(server); ^ TypeError: undefined is not a function </code></pre> <p><strong>Entry point</strong></p> <pre><code>var config = require('./config.json'); var Providers = require('./providers'); var providers = new Providers(config.db); console.log(providers); </code></pre> <p><strong>./providers/index.js</strong></p> <p>Both AssetProvider and UserProvider suffer the same error. I think I only need to show one.</p> <pre><code>module.exports = function Provider(dbConfig) { var UserProvider = require('./userProvider'); var AssetProvider = require('./assetProvider'); this.users = new UserProvider (dbConfig.name, dbConfig.host, dbConfig.port); this.assets = new AssetProvider(dbConfig.name, dbConfig.host, dbConfig.port); } </code></pre> <p><strong>./providers/userProvider.js</strong></p> <p>Problem line marked</p> <pre><code>var mongodb = require('mongodb'); var MongoClient = mongodb.MongoClient; var Server = mongodb.Server; var ObjectID = mongodb.ObjectID; var UserProvider = function (database, host, port) { var server = new Server(host, port, { auto_reconnect: true }); // Error is here this.client = new MongoClient(server); this.client.open(function (error, client) { this.db = client.db(database); }); }; // ...a bunch of prototype stuff... // ... module.exports = UserProvider; </code></pre> <p>From what I have read in other locations online, I don't see anything wrong with my syntax. I have tried the following declaration...</p> <pre><code>function UserProvider(database, host, port) </code></pre> <p>as opposed to</p> <pre><code>var UserProvider = function(database, host, port) </code></pre> <p>Everything else I did was comparable to slapping a car engine with a wrench. The truth is, I simply do not understand what is so wrong here, but I do know that I just want to make a composition of objects across files so that my entry point can readily use all providers through a single object.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload